I am working on creating expandable rows for a table element using this HTML code snippet. The current approach involves alternating between parent rows and multiple rows within tbody elements.
<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 well with static values, but now I want to incorporate Vue.js and utilize a v-for loop with myList data. However, due to the presence of two tbody elements together, I am facing issues implementing v-for directly. Also, wrapping them in a div tag is not feasible as it would break the table structure.
Is there any non-affective element that can be used to group these multiple tbody elements for a v-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>
You can view the fiddle here:
https://jsfiddle.net/jeaxopwf/2/
Below is an 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>