Using indexOf to lookup the first matching row and return data.

Using indexOf to lookup the first matching row and return data.

Chris-B11Chris-B11 Posts: 3Questions: 1Answers: 0

I am using the expression

let index = table.column('Person:name').data().indexOf('Chris')

to return the the first 'Chris' that exists my table's 'Person' column. The value of index appears to be an integer pointing to the the matching column array element that matches 'Chris'. Now I would like to use that index to reference the table.row() to get the table.row().data(). I thought that the following might work:

rdata = table.row(index).data()

It did not. Where have I gone wrong? How should I return the data for the row that matches 'Chris' in the table?

Thanks.

This question has an accepted answers - jump to answer

Answers

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

    The index for the column would be the order the data currently is in, so you would need to ensure the rows are in the same order - so change your second code segment to be:

    let index = table.column('Person:name').data().indexOf('Chris') 
    table.row(':eq(' + index + ')', {order: 'current'}).data()
    

    Colin

Sign In or Register to comment.