I have a table that can be toggled fine with a button or by clicking on the row. The problem is when the 1st column is spanned over 2 or more rows everything goes out of sync. Also would like the bottom border to move under the toggled area and the hovered area background colour to line up with additional rows (currently only works with 1st row because of the rowspan). Hopefully this makes sense and someone can help with this.
$(document).ready(function() {
$("#hide").click(function() {
$(".toggle").hide();
});
$("#show").click(function() {
$(".toggle").show();
});
$("#data tr td").click(function() {
$(this).parents(".pointer").next().toggle();
});
});
table {
border-collapse: collapse;
margin-top: 20px;
}
table,
th {
border: solid 1px;
padding: 10px;
}
tr:hover td {
background: #e5e5e5;
}
.toggle {
display: none;
}
.toggle.active {
display: table-row;
}
.pointer {
cursor: pointer;
border: none;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<button id="hide">Hide All</button>
<button id="show">Show All</button>
<table>
<tr>
<th>header</th>
<th>header</th>
<th>header</th>
<th>header</th>
<th>header</th>
</tr>
<tbody id="data">
<tr class="pointer">
<td style="border-bottom:1px solid;" >DATA1</td>
<td style="border-bottom:1px solid;">data1</td>
<td style="border-bottom:1px solid;">data1</td>
<td style="border-bottom:1px solid;">data1</td>
<td style="border-bottom:1px solid;">data1</td>
</tr>
<tr class="toggle">
<td></td>
<td colspan="4">toggled area 1a</td>
</tr>
<tr class="pointer">
<td style="border-bottom:1px solid;" rowspan="2">DATA2</td>
<td>data2</td>
<td>data2</td>
<td>data2</td>
<td>data2</td>
</tr>
<tr class="toggle">
<td></td>
<td colspan="4">toggled area 2a</td>
</tr>
<tr class="pointer">
<td style="border-bottom:1px solid;">data2</td>
<td style="border-bottom:1px solid;">data2</td>
<td style="border-bottom:1px solid;">data2</td>
<td style="border-bottom:1px solid;">data2</td>
</tr>
<tr class="toggle">
<td></td>
<td colspan="4">toggled area 2b</td>
</tr>
<tr class="pointer">
<td rowspan="3">DATA3</td>
<td>data3</td>
<td>data3</td>
<td>data3</td>
<td>data3</td>
</tr>
<tr class="toggle">
<td></td>
<td colspan="4">toggled area 3a</td>
</tr>
<tr class="pointer">
<td>data3</td>
<td>data3</td>
<td>data3</td>
<td>data3</td>
</tr>
<tr class="toggle">
<td></td>
<td colspan="4">toggled area 3b</td>
</tr>
<tr class="pointer">
<td>data3</td>
<td>data3</td>
<td>data3</td>
<td>data3</td>
</tr>
<tr class="toggle">
<td></td>
<td colspan="4">toggled area 3c</td>
</tr>
</tbody>
</table>