Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dynamic table rowspan in vue.js

Has anybody tried dynamic table rowspan in vue.js?

Below is data

{
    date: '2018-08-14',
    temp_que : 120,
},
{
    date: '2018-08-14',
    temp_que : 120,
},
{
    date: '2018-08-15',
    temp_que : 120,
},
{
    date: '2018-08-15',
    temp_que : 120,
},

Below is html vue

<template v-for="(item, i) in list">
  <tr> 
    <td
      :rowspan=""
      v-if=""
      class="text-center"
      v-text="item.date"
    ></td>
  </tr>
</template>

Question is how I put rowspan when date got same date?

like image 513
Aiden Kim Avatar asked Nov 12 '18 08:11

Aiden Kim


1 Answers

First,you need to count the number of same date, like this: { date: '2018-08-14', same_num:'count', temp_que : 120, },

  <template >
     <tr v-for="(item, i) in list"> 
       <td
         :rowspan="item.same_num"
         v-if="!i? true:item[i-1].date==item[i].date? '':true"
         class="text-center"
         v-text="item.date"
       ></td>
     </tr>
   </template>
like image 138
Joe Avatar answered Sep 18 '22 16:09

Joe