How do I get the cells of a row from the row() api inside rowCallback?

How do I get the cells of a row from the row() api inside rowCallback?

tom99tom99 Posts: 48Questions: 10Answers: 0

Use case: I want to modify CSS classes of cells in the rowCallback.

So, code should look like this:

rowCallback: function (row, data, dataIndex) {
  var cell = <find cell at col index 17 for this row>
  if(something) {
    $(cell.node()).addClass('red');
  }

In many examples, it is done like this:

  $(row).find('td:eq(17)').addClass('red');

But this does not work if some columns are hidden.

Current workaround for me:

  var rowIndex = this.api().row(row).index();
  $(this.api().cell(rowIndex, 17).node()).addClass('red'); 

Thanks!

This question has an accepted answers - jump to answer

Answers

  • colincolin Posts: 15,240Questions: 1Answers: 2,599
    Answer ✓

    Hi @tom99 ,

    Yep, not a workaround, that's the way to go! :)

    Cheers,

    Colin

  • tom99tom99 Posts: 48Questions: 10Answers: 0

    Nice to hear and thanks for the quick answer. :-)

    Although I thought, it should be easier to do with less code. ;-)

This discussion has been closed.