indexOf() only for values depending on input of another column

indexOf() only for values depending on input of another column

CapamaniaCapamania Posts: 229Questions: 79Answers: 5
edited August 2016 in DataTables 1.10

How can I do a https://datatables.net/reference/api/indexOf() for Column_02, but only for the rows with value '1' of Column_01?

Column_01 | Column_02
1|Value_03
1|Value_02
1|Value_01
3|Value_01
5|Value_01

var getData = table.column( 1 ).data().indexOf();

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 61,744Questions: 1Answers: 10,111 Site admin
    Answer ✓

    There are a few options, perhaps the most consise will be to use cells().data() with the row selector (row-selector) as a function, selecting rows based on the data:

    table.cells(
      function ( idx, data, node ) {
        return data[0] == 1l
      },
      1
    ).data();
    

    Allan

  • CapamaniaCapamania Posts: 229Questions: 79Answers: 5
    edited August 2016

    Thanks for the hint Allan. It worked with the cells( rowSelector, columnSelector [, modifier ] ) method from https://datatables.net/reference/api/cells() .

    Regards.

This discussion has been closed.