Bug? [test case included] cell().data() automatically redrawing when set

Bug? [test case included] cell().data() automatically redrawing when set

rhinorhino Posts: 80Questions: 2Answers: 17
edited July 2014 in Free community support

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!

Minimal test case

Note that there is no draw() call after the cell().data() call.

This question has accepted answers - jump to:

Answers

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Answer ✓

    It seems like calling cell().data()DT with data automatically redraws the table and updates the cached data

    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 the draw() 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

  • rhinorhino Posts: 80Questions: 2Answers: 17
    edited July 2014

    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.

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Answer ✓

    Is there any way to update the data in the cell, without writing the change to the innerHTML?

    I'm afraid not no.

    Alternatively, is there a way to hook into the orderDT event before data has been ordered?

    Heh - not that either...

    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.

    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 call order() after you have updated the data.

    Allan

  • rhinorhino Posts: 80Questions: 2Answers: 17
    edited July 2014

    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 call order() after you have updated the data.

    I think I'll have to go this route.

    Thanks Allan :)

This discussion has been closed.