Reputation: 12857
I have this html which makes expandable rows for table element, however its approach works like this:
<tbody class="js-table-sections-header">Parent row</tbody>
<tbody>Multiple rows</tbody>
<tbody class="js-table-sections-header">Parent row</tbody>
<tbody>Multiple rows</tbody>
<tbody class="js-table-sections-header">Parent row</tbody>
<tbody>Multiple rows</tbody>
It works fine with static values.
However at this point, I want to use Vue and use a v-for
for my list. But as there are 2 <tbody>
elements, first, I can't use v-for
directly, and secondly (as I can't wrap them in a <div>
to obtain a single parent element) I can't create a component.
My question is: Is there a way to use as a non-affective element tag that I can wrap these multiple tbody
elements into so I can for loop?
<template>
<non-affective-tag v-for="x in myList">
<tbody class="js-table-sections-header">One row</tbody>
<tbody>Multiple rows</tbody>
</non-affective-tag>
</template>
Here you can see the fiddle:
https://jsfiddle.net/jeaxopwf/2/
And down below, you can see the example:
$('.js-table-sections-header').click(function() {
$(this).toggleClass('open');
})
.js-table-sections-header > tr {
cursor: pointer;
}
.js-table-sections-header > tr > td:first-child > i {
-webkit-transition: -webkit-transform 0.15s ease-out;
transition: transform 0.15s ease-out;
}
.js-table-sections-header + tbody {
display: none;
}
.js-table-sections-header.open > tr {
background-color: #f9f9f9;
}
.js-table-sections-header.open > tr > td:first-child > i {
-webkit-transform: rotate(90deg);
-ms-transform: rotate(90deg);
transform: rotate(90deg);
}
.js-table-sections-header.open + tbody {
display: table-row-group;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table class="js-table-sections table table-hover">
<thead>
<tr>
<th style="width: 30px;"></th>
<th>Name</th>
<th style="width: 15%;">Access</th>
<th class="hidden-xs" style="width: 15%;">Date</th>
</tr>
</thead>
<tbody class="js-table-sections-header open">
<tr>
<td class="text-center">
<i class="fa fa-angle-right"></i>
</td>
<td class="font-w600">Sara Holland</td>
<td>
<span class="label label-danger">Disabled</span>
</td>
<td class="hidden-xs">
<em class="text-muted">June 7, 2015 12:16</em>
</td>
</tr>
</tbody>
<tbody>
<tr>
<td class="text-center"></td>
<td class="font-w600 text-success">+ $92,00</td>
<td>
<small>Paypal</small>
</td>
<td class="hidden-xs">
<small class="text-muted">June 19, 2015 12:16</small>
</td>
</tr>
<tr>
<td class="text-center"></td>
<td class="font-w600 text-success">+ $54,00</td>
<td>
<small>Paypal</small>
</td>
<td class="hidden-xs">
<small class="text-muted">June 16, 2015 12:16</small>
</td>
</tr>
<tr>
<td class="text-center"></td>
<td class="font-w600 text-success">+ $84,00</td>
<td>
<small>Paypal</small>
</td>
<td class="hidden-xs">
<small class="text-muted">June 26, 2015 12:16</small>
</td>
</tr>
<tr>
<td class="text-center"></td>
<td class="font-w600 text-success">+ $24,00</td>
<td>
<small>Paypal</small>
</td>
<td class="hidden-xs">
<small class="text-muted">June 27, 2015 12:16</small>
</td>
</tr>
</tbody>
<tbody class="js-table-sections-header" v-for="list in myList">
<tr>
<td class="text-center">
<i class="fa fa-angle-right"></i>
</td>
<td class="font-w600">Maya</td>
<td>
<span class="label label-danger">Disabled</span>
</td>
<td class="hidden-xs">
<em class="text-muted">June 7, 2015 12:16</em>
</td>
</tr>
</tbody>
<tbody>
<tr>
<td class="text-center"></td>
<td class="font-w600 text-success">+ $82,00</td>
<td>
<small>Paypal</small>
</td>
<td class="hidden-xs">
<small class="text-muted">June 19, 2015 12:16</small>
</td>
</tr>
<tr>
<td class="text-center"></td>
<td class="font-w600 text-success">+ $24,00</td>
<td>
<small>Paypal</small>
</td>
<td class="hidden-xs">
<small class="text-muted">June 16, 2015 12:16</small>
</td>
</tr>
<tr>
<td class="text-center"></td>
<td class="font-w600 text-success">+ $34,00</td>
<td>
<small>Paypal</small>
</td>
<td class="hidden-xs">
<small class="text-muted">June 26, 2015 12:16</small>
</td>
</tr>
<tr>
<td class="text-center"></td>
<td class="font-w600 text-success">+ $29,00</td>
<td>
<small>Paypal</small>
</td>
<td class="hidden-xs">
<small class="text-muted">June 27, 2015 12:16</small>
</td>
</tr>
</tbody>
</table>
Upvotes: 2
Views: 1570
Reputation: 43899
You can use the template
tag with v-for
.
<template>
<template v-for="x in myList">
<tbody class="js-table-sections-header">One row</tbody>
<tbody>Multiple rows</tbody>
</template>
</template>
Upvotes: 6