Its a common requirement, and not Laravel specific, so a simple google returns many results
https://stackoverflow.com/questions/171027/add-table-row-in-jquery
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
So I have an ajax with json results which shows about 3 results at the moment. And I want to be able to populate the tbody with tr depending on the number of the results. And of course populating the td with the actual results per each tr. Hope I am making sense here. Here is what I am using to loop through my results.
if(res.length) {
$.each(res, function(i, element){
var id=element.id;
var department=element.department;
$('#custom-table-body tr').each(function() {
});
console.log(department);
});
}
Console logging department shows 3 results. So that basically means that the table to create 3 tr. And Inside each of those tr, there will be td for their id and department.
Example for expected result:
<tr>
<td>1</td>
<td>IT</td>
<td>John</td>
<td>Male</td>
<td>America</td>
<td>48484</td>
<td>active</td>
</tr>
<tr>
<td>2</td>
<td>IT</td>
<td>Smith</td>
<td>Male</td>
<td>America</td>
<td>3232</td>
<td>active</td>
</tr>
<tr>
<td>3</td>
<td>IT</td>
<td>Wick</td>
<td>Male</td>
<td>America</td>
<td>3333</td>
<td>active</td>
</tr>
I do not know where to even begin with this.
Its a common requirement, and not Laravel specific, so a simple google returns many results
https://stackoverflow.com/questions/171027/add-table-row-in-jquery
Please or to participate in this conversation.