Why data is not updated
Why data is not updated
magicscreenshot@gmail.com
Posts: 3Questions: 2Answers: 0
I have the following code :
var drivers = [];
$("#tblDrivers").dataTable({
"lengthMenu": [[25, 50, 100], [25, 50, 100]],
data: drivers,
columns: [
{},
{ data: 'Name' },
{ data: 'CompanyName' },
{ data: 'PhoneNo' },
{ data: 'Email' },
{ data: 'Truck' },
{ data: 'Trailer' },
{ data: 'IsVistracksAdded' },
]
});
then I get data and want to update table:
driverSignalR.client.onGetDrivers = function (data) {
drivers = data;
var table = $('#tblDrivers').DataTable();
table.data = drivers;
table.rows().invalidate().draw();
}
new data is coming (I see it in the debugger), but nothing happened on client side. What I do wrong?
This discussion has been closed.
Answers
What format is your data in?
Instead of using this:
Depending on the format of
drivers
you should just userows.add()
.Kevin
It works if I call
table.draw();
after rows.add();
very unclear API....
There is a lot to the API to understand.
You can also use:
rows.add().draw();
Kevin
You need to call
draw()
when you want the table to update for the latest configuration (as noted in therows.add()
documentation) so that you can optionally queue up multiple changes before drawing the table to allow for better performance.Allan