Calling addClass on 'out of page' tr has no effect

Calling addClass on 'out of page' tr has no effect

darrenmdarrenm Posts: 29Questions: 11Answers: 0

I have a table which uses pagination and I need to be able to add/remove classes on rows that aren't on the current page. When I make the call to addClass it appears to be successful but when I go to the page the row is on, the class has not been applied.

This is my code:

$(table.row("#row-10").node()).addClass("myclass");

var table is the result of the call to .DataTable()

If the row is currently visible it works as expected.

Note I also tried this (as suggested in the sample for node()):

table.row("#row-1").node().addClass("myclass");

But this throws a 'addClass is not a function' error.

What am I doing wrong?

This question has an accepted answers - jump to answer

Answers

  • colincolin Posts: 15,237Questions: 1Answers: 2,598

    Hi @darrenm ,

    That looks about right, so nothing obvious there. We're happy to take a look, but as per the forum rules, please link to a test case - a test case that replicates the issue will ensure you'll get a quick and accurate response. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.

    Cheers,

    Colin

  • darrenmdarrenm Posts: 29Questions: 11Answers: 0

    OK thanks. I tried setting up a simple test case but of course it works as expected - ie I can't reproduce the problem. This is a massively complex table, the initialisation section alone is over 400 lines of code and there are so many other things going on, it would be very difficult to simulate the whole thing in a standalone test case. And unfortunately with respect to seeing the problem on my site, the timing is crucial because the table is tracking live events that only occur at very specific times of the day. I wouldn't even know where to start.

    Anyway it's obviously not that specific bit of code that's at fault because it does work in the simple test case, at least you helped me establish that. I'll have a play around and see if I can pinpoint the problem by commenting out initialisation code until it stops happening, that's what I usually do with these problems! 9 times out of 10 something else somewhere is causing it to break.

  • colincolin Posts: 15,237Questions: 1Answers: 2,598
    Answer ✓

    Hi @darrenm ,

    Test cases are good for that - at least elimination is one less thing it could be. Good luck with solving it.

    Cheers,

    Colin

This discussion has been closed.