Refresh rows without ajax call
Refresh rows without ajax call

Description of problem:
Hi,
I have a datatable populated by ajax calls.
I use the createdRow callback to add a class on some rows based on some local sates.
When a state changes I call the draw() method but I see that it sends an ajax request I don't need.
Is it possible to execute the createdRow callback or refresh the table without sending an ajax request?
Maybe the draw() method could take a parameter to refresh the table with current data?
This question has an accepted answers - jump to answer
Answers
Just deactivate "serverSide" and the problem will be gone.
https://datatables.net/reference/option/serverSide
With "serverSide" activated an ajax call is required when redrawing the table because Editor may not have all the required rows downloaded from the server yet.
Are you saying you are calling
draw()
increatedRow
?Please post your Datatables code so we can see what you are doing. If you are calling
draw()
in -=option createdRow` we might be able to offer suggestions to eliminate the call.Kevin
You mean you disable "serverSide", call draw() then enable "serverSide"? I've looked at the API and did not found how to do that.
The code look like this:
But the draw call is not done in
createdRow
. It is done elsewhere when some selected state changes.No, I meant to disable "serverSide" completely. Do you really need it? Most people don't really need it - and it can complicate things a lot.
We really need it as we want to handle tables with million of rows.
And do you feel a delay or anything noticeable due to the additional ajax call? I tested it myself and it didn't cause any client side delays to be honest.
To answer this specific question, the answer is no. If you have server-side processing enabled, and that's fair enough with millions of rows, any draw is going to trigger an Ajax request. That's the whole point of server-side processing - a draw requests what to display from the server.
If you need to update classes based on a local state that can change without needed a draw, do it using the API. Iterate over the rows (
rows().every()
androw().node()
for example) and update the classes as needed.It does mean that you'll have the logic both in
createdRow
and the loop, but I'm sure that could be pulled into a custom function to ensure code reuse.Allan