Getting/Setting Cell Data Using Explicit Indexes
Getting/Setting Cell Data Using Explicit Indexes
Hi. I'd like to perform an action on the content of numerous cells of my DataTable using jQuery. Things were going quite well. I used the following:
$('input:regex(id,^' + rootNodeName + '[A-Z0-9]*$)').each(function(index, value) {
// Do stuff to each element with an ID matching the regex
}
I was laughing and singing my own praises, when suddenly the fun ended. It dawned on me that this doesn't work for rows who aren't currently visible. So all the rows on page 1 were changed correctly, but pages 2 and up had no changes. Is there a way around this?
My workaround was to use the row() and cell() methods of the API. I've been a little bit successful, but the examples only show how to operate on rows and cells that have been clicked, so they can be referred to implicitly, a la $(this).
I need to change rows by providing explicit indexes e.g., row[3].cell[0] or something like that. Can anyone offer a suggestion? Thanks.
This question has an accepted answers - jump to answer
Answers
I needed to get a handle for a specific row, so I used the createdRow feature of the DataTables definition. This way I have an ID that I can use as a selector for each targeted row or cell.
I have an ID column, so I used that to assign an ID attribute to the TR with a concatenated value.
You can also target specific cells with the createdCell feature of the ColumnDefs section. This adds an attribute to my second column, setting ID equal to a concatenated value. the field is the rating field, so I used "rating" as part of the value.
However, I don't have any idea how paging affects this. If you look at the DOM of the displayed table, when you filter row, they are removed from the visible table. I don't know where DT holds the complete set of data, so someone else will have to point you in that direction if needed.
Thank you!