As simple as it is, the idea of my question is that I have an array of JSON objects, I want to dynamically append these objects to an HTML table, and in the last td I want to add a remove button so I can remove the row.
Actually I've spend several days looking for an efficient solution but unfortunately didn't find anything.
I've tried to do it in my own and this is what I came up with:
for (var i = 0; i < objArr.length; i++) {
var tr = "<tr>";
var td1 = "<td>" + objArr[i]["empID"] + "</td>";
var td2 = "<td>" + objArr[i]["fname"] + "</td>";
var td3 = "<td>" + objArr[i]["lname"] + "</td>";
var td4 = "<td>" + objArr[i]["phone"] + "</td>";
var td5 = "<td>" + objArr[i]["address"] + "</td>";
var td6 = "<td>" + objArr[i]["deptID"] + "</td>";
var td7 = "<td>" + objArr[i]["email"] + "</td>";
var td8 = "<td>" + '<button id="' + objArr[i]["empID"] + '" value="' + objArr[i]["empID"] + '" onclick="onClickDelete(' + objArr[i]["empID"] + ')">Delete</button>' + "</td></tr>";
$("#dataTable").append(tr + td1 + td2 + td3 + td4 + td5 + td6 + td7 + td8);
}
But as you may notice, this is not the efficient manner to accomplish that. I'm pretty sure that definitely there is a better solution for this.
So could anyone please provide any suggestions