Table updating without draw() call when updating row's data
Table updating without draw() call when updating row's data
We're using 1.10.16.
When updating a row, the table is refreshing without a call to update. As we understand it, the table should only refresh on a draw() call.
We have a simple function that receives some data and updates the table (if the data already contains data with a matching uniqueId), or adds a new row.
addToTable(someData) {
let row = this.dt.row("#id_" + somedata.uniqueId);
if (row.length) {
row.data(someData);
} else {
this.dt.row.add(someData);
}
}
When we call row.data() to change the data stored in the row, the row updates - _except _for the column that contains the uniqueID field.
Using row.add() only updates after a draw() call (which we have on a timer).
Columns
columns: [
{ title: "a", data: "uniqueid", render: rs},
{ title: "b", data: "b", render: rb},
{ title: "c", data: "c" },
{ title: "d", data: "d", render: rd},
{ title: "e", data: "e", render: re},
{ title: "f", data: "f", render: rf},
{ title: "g", data: "g" },
{ title: "h", data: "h" },
{ title: "i", data: "i" },
{ title: "j", data: "j", render: rj},
],
Many thanks for your help.
Answers
When you say refreshing do you mean sorting, etc is taking place?
It is expected the using
row.data(someData);
will update the row and the new data is displayed. Usingdraw()
will apply searching and sorting to the table.Kevin
Many thanks for the reply.
When I say refreshing, I mean the new data is being instantly updated to the table, and the table redrawn.
We were under the assumption that row.data(somedata).draw() was necessary to re-render the table.
We may have a pop-up menu above the table, and wouldn't want the data changing beneath.
Again, is sorting and searching taking place with
row.data(somedata)
when not usingdraw()
? It sounds like it when you say "and the table redrawn".Kevin
Yes, it's sorting.
Rather than the expected behaviour of nothing happening to the table until a draw() call.
This example shows that the row data is updated but sorting does not take place:
http://live.datatables.net/xasugipe/1/edit
Click the button to see Ashton Cox's data updated without using
draw()
. The table is not sorted.If the behavior is different in your environment then that suggests something else in your script is calling
draw()
. Can you post a link to your page or update my test case to replicate the issue?Kevin
Many thanks for that. I'll have a look at that.
I'm not sure it is sorting. It's just redrawing the incoming rows if there's an existing row matching the uniqueId.
I'm afraid I can't post anything, but I'm happy to include limited info regarding operation and settings.
I've had a look at the demo. We don't want any updates until a draw() is called. I thought that was the default behaviour.
It looks like we'll have to cache the changes and update manually.