API: row (tr_row) .data ()
API: row (tr_row) .data ()
jabber
Posts: 23Questions: 1Answers: 0
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)
This discussion has been closed.
Answers
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 - seerow-selector
) into a DataTables internal index (try running justconsole.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
Now i understand that the internal index is tr_row._DT_RowIndex, is it true ?
Yes. It is an internal index and shouldn't be used externally.
Allan
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?
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
Wow, very fast answer and thank you also for your accuracy.