Clear CSS from cells 2 and 3
Clear CSS from cells 2 and 3
NoBullMan
Posts: 61Questions: 17Answers: 2
Link to test case:
Debugger code (debug.datatables.net):
Error messages shown:
Description of problem:
How can I clear/remove a CSS class from cells 2 and 3 of each row?
I can do this from within rowCallback or rowCreated but not sure how to do it from a jQuery function.
Created this way:
rowCallback: function (row, data, index) {
if (data.BINCODE_COUNT > 1) {
$('td:eq(1)', row).removeClass('alertRow').addClass('duplicateBincode');
$('td:eq(2)', row).removeClass('alertRow').addClass('duplicateBincode');
}
At some point, I need to remove duplicateBincode class from these cells in each row.
Answers
I'm guessing what you want is something like this:
If this doesn't help then please describe when and what conditions you want to remove the class
duplicateBincode
.Kevin
Thank you Kevin.
I was trying to avoid reloading the table as there are a lot of data and abit time consuming. Reloading the table would do it as the condition to apply the style would no longer be true.
I thought maybe there is a way to use the reference to datatable and remove the css from the rows. Something maybe along the lines of:
Apparently, these don't work:
rowCallback
executes each draw event (search, sort, page) against the rows that are displayed on the page. I was thinking thatdata.BINCODE_COUNT
might change and you would want to update the classes based on the change. For the change to take affect you would calldraw()
.createdRow
is different in that it only runs once when each row as its created.If you just want to remove the class from the whole table I think this will work:
It uses
rows().nodes()
to get all the -tag trelements.
-api to$()` converts the result into a jQuery object that you can use jQuery removeClass().You could loop through with
rows().every()
if you want to do some comparisons, for example:Kevin
Hi Kevin
wouldn't these attempt to remove the class from the rows instead of the certain cells within each row? I think these options attempt to remove a class from tr rather than td.
That's how the class is assigned: to cell 2 and 3 of certain rows and not the entire row.
Also, the second example you provided is same as one of my attempts that did not work. You mentioned:
and I had tried:
Yes you are right. You can do the same with
column().nodes()
. Look at the example in the docs.Kevin
I found that either of below two methods works; it also removes the select checbok from column 1. I couldn't find an easy way, or any way, of using column() API.
Thank you for your help and your patience. It is much appreciated.
Doing this didn't work?
Repeat for the other columns.
Kevin
Also you probably can use
columns().nodes()
to removeClass() from both columns. Note the addition offlatten()
in the example. Usecolumns( 1,2 ] ).nodes()....
.Kevin