How does the node() APIs work?

How does the node() APIs work?

kthorngrenkthorngren Posts: 20,297Questions: 26Answers: 4,768
edited June 2023 in DataTables 1.10

There isn't a problem just trying to understand how Datatables works behind the scenes. When using row().node() or cell().node() Datatables retrieves the current node information. Take this example:
https://live.datatables.net/qomibuto/1/edit

Change Ashton Cox's Office, go to another page and click the button to get Ashton's data. The updated select value is displayed. The test case triggers nothing to update Datatables. I wonder if Datatables updates is cache with the current page HTML when changing pages. How does this work?

Kevin

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 61,697Questions: 1Answers: 10,102 Site admin
    Answer ✓

    Excellent question - there are a few nuanced things going on here, but ultimately it breaks down to the fact that you are getting the value from the DOM node (the select) not from DataTables.

    The node() methods will go into DataTables cache and get the node for the item selected (a td or tr typically). DataTables holds a reference to each row and cell node inside it, which allows to to remove elements from the document and then re-insert them (for paging and column visibility), but also so we can access them via the API.

    You are using row(2) which is an index selector, so regardless of the paging or filtering, it will always get the row that is index 2 in its internal data array (Ashton's row in this case - funny, Colin always uses that row for testing as well!). The array is not sparse, so if you were to delete that row (or any preceding it) index 2 would no longer refer to that row! That is something I might change in future.

    The upshot of all this, is that you are basically just querying a standard select element. The end user changes it's value, its .value gets updated by the browser.

    Does that help clarify things, or just muddy the water further?

    Allan

  • kthorngrenkthorngren Posts: 20,297Questions: 26Answers: 4,768

    That helps thanks!

    Ashton's row in this case - funny, Colin always uses that row for testing as well!

    Yep, Ashton is my buddy :smile:

    Kevin

Sign In or Register to comment.