Refresh table
Refresh table
cranworth
Posts: 20Questions: 10Answers: 0
I wish to refresh my data table upon the addition of a new row. Row addition is achieved with data collected from an input form and its data submitted via ajax (using JQuery). It might be worth mentioning that the data displayed by the datatable is NOT an ajax source but a javascript object array (i.e. setting the 'data' option in datatable's initialization).
var table_content = '[{"col-name-1":"data"}, {"col-name-2":"data"}]'; // content from php
// table init
var data_table = $('#div_selector').DataTable({
data: table_content,
/*
* Other options omitted
*/
});
After adding a row on the server, I update table_content
with the new data. How do I now refresh the table?
This discussion has been closed.
Answers
Use
clear()
androws.add()
to first clear the old data, and the secondly add the new data.Allan
Thanks. I tried
clear()
androws.add()
. I get this error message on chrome, Screenshot here: http://postimg.org/image/o5ryv9um9/It is strange because the data passed was in the same format as used in the initialization of the table.
Are you adding a single row? If so use
row.add()
.Allan
I used
clear()
to clear the table and thenrows.add()
to add all rows. Doesn't update the table. It's strange. Here is a snippet of my code:the
response
is a string containing the javascript array declaration (returned from server).I would probably need a link to the page to see what is happening then. That should work.
Allan
I have PM the link to you. thanks