The problem is that it will not allow me to insert a row into my table using jQuery. I tried using .eq()
with index to find the correct position to insert and .after()
to insert the row. However, it will not add the row.
This is the HTML:
<table class="ResultsTable" hidden="hidden">
<thead class="header">
<tr>
<td class="rankColumn"></td>
<td class="nameColumn"></td>
<td class="ageColumn"></td>
</tr>
</thead>
<tbody id="resultsTableBody"></tbody>
</table>
This is my jQuery:
function insert(data){
$('#resultsTableBody > tr')
.eq(data['Status'] - 1).after('<tr>' +
'<td class=\'rankColumn ' + data['Rank'] + ' \' ></td>' +
'<td class=\'nameColumn\'>' + data['Name'] + '</td>' +
'<td class=\'ageColumn\'>' + data['Age'] + '</td>' +
'</tr>');
}
Why is it that it wont insert anything into the table body? Rank is like an index which represents how high up the list a row should be. With rank being from 1 to 3. So this code should insert a row into the correct position in the table. The table is empty to start with.
Expected result is:
1 | John | 24
1 | Bob | 19
1 | Misha | 27
2 | Laura | 22
3 | Hannah | 31
3 | Paul | 43
They should be placed in order like above based on their rank. However, the table just shows the header and the body is blank. Where am I going wrong?
The data will all not be available when inserting they will be retrieved one at a time and it will find its place in the table based on the others.