API: row (tr_row) .data ()

API: row (tr_row) .data ()

jabberjabber Posts: 23Questions: 1Answers: 0
edited March 2017 in Free community support

Hi,
i 'd like to understand better how datatable retrieve data on api function of "table.row (tr_row) .data ()" where tr_row is the <tr> tag of the related row.
For example, If i add an event handlers on the <tr> tag table because i want to retrieve the internal row data object (named also cache), how does that api work ?
As identifier of the internal object, does api use the tr.id or the tr._DT_RowIndex?
(i might have also made a wrong assumption)

Answers

  • allanallan Posts: 63,873Questions: 1Answers: 10,528 Site admin

    The way the data() methods work are that they retrieve a cached data store that DataTables maintains for each row. row() will select the row in question, transforming the node (or jQuery object, id or a number of other options - see row-selector) into a DataTables internal index (try running just console.log( table.row( tr_row ) ); in the console and you'll see the index) which allows the data chained method to look up the data based on that index.

    Does that make sense?

    Allan

  • jabberjabber Posts: 23Questions: 1Answers: 0

    Now i understand that the internal index is tr_row._DT_RowIndex, is it true ?

  • allanallan Posts: 63,873Questions: 1Answers: 10,528 Site admin

    Yes. It is an internal index and shouldn't be used externally.

    Allan

  • jabberjabber Posts: 23Questions: 1Answers: 0

    Thank you very much Allan.
    But little curiosity, as internal index date (tr_row._DT_RowIndex), why didn't you used the "id" attribute of the <tr> tag? For Security Reasons?

  • allanallan Posts: 63,873Questions: 1Answers: 10,528 Site admin

    No - because the id might be something else that is defined by the user. It is also valid to not have an id for the row, so that situation needs to be considered.

    The row index parameter only means anything to DataTables - specifically to its internal data storage array. It means nothing externally, unlike the id attribute, which is specifically designed to identify the row in the document.

    Allan

  • jabberjabber Posts: 23Questions: 1Answers: 0
    edited March 2017

    Wow, very fast answer and thank you also for your accuracy.

This discussion has been closed.