Something like indexOf to use HTML5 data-filter attribute instead of cell content to locate a row

Something like indexOf to use HTML5 data-filter attribute instead of cell content to locate a row

darrenmdarrenm Posts: 29Questions: 11Answers: 0

I am trying to use indexOf to locate a cell that contains some text. The cell has the text wrapped in <a> tags and so indexOf returns -1. If I remove the <a> tags and just have the cell contain the text I'm searching for, it works fine.

I have added data-filter attributes to each <td> but indexOf doesn't seem to use them. Is there a way I can get it to, or some other way I can locate a specific row that has the text in the column I am looking for?

I am trying to locate the row index for the row I want so I can then draw the page that contains it. The JumpToData plug-in has the same issue, it won't find my row because of the <a> tags.

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,457Questions: 1Answers: 10,466 Site admin
    Answer ✓

    I have added data-filter attributes to each <td> but indexOf doesn't seem to use them.

    Use cells().render() rather than rows().data() (or any of the other *.data() methods) if you want to get orthogonal data.

    e.g.:

    var idx = table.cells( null, 0 ).render( 'search' ).indexOf( 'myText' );
    

    Allan

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

    Hi @darrenm ,

    There's a lot going on there. We're happy to take a look, but it would help, as per the forum rules, if you could link to a running test case showing the issue so we can offer some help. 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

    Thanks Colin, I will make sure to do that in future. In this case though, Allan has nailed it, so thank you.

This discussion has been closed.