I'm working on this HTML Table with drilldown functionality, it works for one column but I cant display a third column, I want to click on subcategory column and display another column but Im stuck in this part .
This is my JS code
function toggleVisibilitySubcategory() {
$('table.drillDown th:nth-child(2)').toggle();
$('table.drillDown tbody td:nth-child(2)').toggle();
}
function toggleVisibilityItem() {
$('table.drillDown th:nth-child(3)').toggle();
$('table.drillDown tbody td:nth-child(3)').toggle();
}
$(function () {
toggleVisibilitySubcategory();
toggleVisibilityItem();
$('table.drillDown').each(function() {
var $table = $(this);
$table.find('.parent').click(function() {
console.log( "click on parent" );
$(this).nextUntil('.parent').toggle();
if ($(this).find("td:hidden").length > 0) {
toggleVisibilitySubcategory();
}
});
var $childRows = $table.find('tbody tr').not('.parent').hide();
$table.find('button.hide').click(function() {
$childRows.hide();
});
$table.find('button.show').click(function() {
$childRows.filter('.child').show();
});
$table.find('tr.child').click(function(){
$(this).nextUntil('.child').show()
});
});
});
This is the HTML table.
<table class="drillDown" border="1" align="center">
<thead>
<th>Category</th>
<th>Subcategory</th>
<th>Item</th>
<th>LW</th>
</thead>
<tbody>
<!--PARENT ROW-->
<tr class="parent">
<td>Category 1</td>
<td></td>
<td></td>
<td></td>
</tr>
<tr class="child" >
<td> </td>
<td>Subcategory_1 A
<td>a</td>
<td></td>
</tr>
<tr class="child">
<td> </td>
<td>Subcategory_1 B</td>
<td>a</td>
<td></td>
</tr>
</tbody>
</table>