Selecting rows by dynamically created class
Selecting rows by dynamically created class
NoBullMan
Posts: 104Questions: 31Answers: 3
Link to test case:
Debugger code (debug.datatables.net):
Error messages shown:
Description of problem:
To access some table rows easily later on during some application processing, I assigned classes to rows based on some column values:
Added here:
myTable = $("#MyTable").DataTable({
....
rowCallback: function (row, data, index) {
$(row).addClass('row_' + data.SOMECODE);
...
}
});
Later, in an event handler:
var someCode = data.SOMECODE; // Let's say 31038
myTable.rows("'.row_" + someCode + "'").every(function (rowIdx, tableLoop, rowLoop) {
....
});
Here, I get:
Syntax error, unrecognized expression: '.row_31038'
Normally, I can access rows like:
myTable.rows('.selected').every(function (rowIdx, tableLoop, rowLoop) {
This discussion has been closed.
Answers
I think the problem is with the single quotes. You probably want something like this:
Kevin
Thanks. I now proceed to open my eyes!
The reason I am doing this is that I have a checkbox select column to allow users to select records to delete. Some selected records can have duplicate column value (in one column, called BINCODE. I need to be able to iterate through the selected records, group by the duplicate column, set one as "selected" and remove "selected" class from others. This is why I was adding a class called "row_" + BinCode to thos rows so I could easily find/group them.
This does not seems to be correct, probably because of the way I am selecting row.
I need to be able to keep the selected record if status = 3 or last modified is newer and unselect others.
I am not sure if I am doing this (i.e., selecting records) the right way.
If you are using the Select extension then you will probably want to use the
row().select()orrows().select()androw().deselect()orrows().deselect()APIs. Maybe something like this:Or within the
rows().every()loop use something like this:Maybe you can post a link to your page or a test case replicating your solution so we can see exactly what you have to offer suggestions.
https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case
Kevin
Thank you Kevin; this helped a lot.