1
I have no advanced knowledge with jquery and need to go through all lines of an HTML table and hide the Line entire case the column from of the number 5 (JUS) be empty and update the sequence numbering of the first column Id, example:
I want to hide the whole row if the 5 and 6 (and the rest if there is 7,8,n...) column is empty:
I had to hide the columns and used the code below suggested and accepted by Felipe Duarte in that post How to go through all columns of a jquery table and hide if empty
var i = 1;
$('table.grid tr td').each(function (el) {
if ($(this).text() == '') {
$('table.grid td:nth-child(' + i + '), th:nth-child(' + i + ')').hide();
}
i++;
})
This is the current structure of my table:
<table class="grid">
<thead>
<tr class="head">
<th>ID</th>
<th>Empresa</th>
<th>PAR</th>
<th>Data</th>
<th>JUS</th>
<th>ST</th>
</tr>
</thead>
<tfoot>
<tr>
<td colspan="6">1 </td>
</tr>
</tfoot>
<tbody>
<tr>
<td>A1</td>
<td>A2</td>
<td>A3</td>
<td>A4</td>
<td>A5</td>
<td>A6</td>
</tr>
<tr>
<td>B1</td>
<td>B2</td>
<td>B3</td>
<td>B4</td>
<td></td>
<td>B6</td>
</tr>
<tr>
<td>C1</td>
<td>C2</td>
<td>C3</td>
<td>C4</td>
<td>C5</td>
<td>C6</td>
</tr>
</tbody>
</table>
Instead of manipulating the DOM to do this, you didn’t think to do this back-end check and send only the list that should be populated in the table?
– BrTkCa
Yes, but at the moment it is not viable I have to do something manipulating the DOM.
– hard123
Got it @Adrianosuv, is that an end-point filter would solve much more perfomatic and elegant, or even in receiving the data on the front (if the request is ajax) - both forms would not need to reassemble the table once created.
– BrTkCa
@Lucas Costa I will take into consideration this alternative also is that my problem is that I need is with it working perfectly today! rs To in a sweat!!
– hard123