datatable.row().node() addClass() does'n work

datatable.row().node() addClass() does'n work

beklightbeklight Posts: 4Questions: 1Answers: 0
edited September 2022 in Free community support

Link to test case:
Debugger code (debug.datatables.net):
Error messages shown:
Description of problem:
var customerId = 5; //for example
var row = datable.row({id:customerId}).node();
$(row).addClass('selected');

//It selects first row which has id:0
//WHY it doesn't select row with id:5 ?

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,531Questions: 1Answers: 10,474 Site admin
    Answer ✓

    {id:customerId} isn't something that the row-selector supports. It's a nice idea for a future feature, but at this time you would need to do something like:

    table.row((idx, data) => data.id === customerId).node()
    

    Allan

  • beklightbeklight Posts: 4Questions: 1Answers: 0

    Thank you very much. I found enother way to solve my issue but your version I gess better.

    var customerId = 5;
    table.rows().every(function(){
    var customer = this.data();
    if (customer.id === customerId) {
    $(this.node()).addClass('selected');
    }
    })

  • allanallan Posts: 63,531Questions: 1Answers: 10,474 Site admin

    The benefit of my version is performance. However, your own one does the job nicely as well - nice one!

    Allan

Sign In or Register to comment.