Append column and row to table populated by JSON object array data
Append column and row to table populated by JSON object array data
What's the best approach for adding another column and rows? I've done this with the render function for data-tables where the columns are defined manually but not sure how this works with columns generated from an array, i.e. is there a way to append additional columns, something like columns:data.columns , columns: { "edit": "edit link" }. Below is the working current code that reflects the API data columns and values. I'd prefer not to build the edit link data on the server and append it to the array since the structure of that data is different and logic on the server side but I may have to if there's not a way to handle this on the client js script.
var table = $('#editorView').DataTable({
destroy: true,
data: data.data,
"columns": data.columns,
responsive: true,
});
This question has an accepted answers - jump to answer
Answers
For the columns you would need to modify your
data.columns
array before you initialise the table. DataTables does not currently support dynamically adding and removing columns I'm afraid.For rows, you could either take the same approach, or use
row.add()
to add a row via the API.Allan