Bug? [test case included] cell().data() automatically redrawing when set
Bug? [test case included] cell().data() automatically redrawing when set
It seems like calling cell().data()
with data automatically redraws the table and updates the cached data. However, the documentation for cell().data()
indicates otherwise:
Note that when used as a setter, this method sets the data to apply to the table, but does not update the table's internal caches of data until the
draw()
method is called.
Is it intended to automatically update and redraw the table? The behavior indicated in the documentation would actually be helpful for my current situation!
Note that there is no draw()
call after the cell().data()
call.
This question has accepted answers - jump to:
Answers
No it doesn't. It does set the
innerHTML
property of the cell, so you see the update immediately. But the data processed by DataTables is not updated until thedraw()
method is called.You can see this by applying a search for your data just before the data is updated: http://live.datatables.net/zojasem/2/edit . If you were to add a
draw()
call after the data update, it would show the row.I've just committed a change to the docs to note this, and I'll deploy to the site shortly.
Allan
Ah, I see. Thanks allan.
Is there any way to update the data in the cell, without writing the change to the innerHTML?
Alternatively, is there a way to hook into the
order
event before data has been ordered? What I'd like to do is update the data of the table when someone clicks a sortable column header, but update the data before it has been ordered.I'm afraid not no.
Heh - not that either...
Ah I see. There are a couple of options in that case. Firstly, depending on what exactly you want, if you want an area that can be clicked to update the column then you could add your event handler to a child element in the header cell and
stopPropagation()
.Another option would be to detect the DataTables default added click event listener and then attach your own. You could either use
order.listener()
or add your own that would callorder()
after you have updated the data.Allan
I think I'll have to go this route.
Thanks Allan :)