How to access rows that are removed from view during a filter using the default input field filter?

How to access rows that are removed from view during a filter using the default input field filter?

suttsutt Posts: 10Questions: 1Answers: 0

See the following example on JSFiddle: https://jsfiddle.net/84Luetjh/

Run the example, and click on the Ashton or Tiger rows. When you do, because they share the same data-test value, "match", they both are selected/deselected when you click either of those rows. This is the behavior I want.

Now, start again, with no selected rows. Use the input Search field filter above the table to search for Ashton (enter at least ash). When you do this, the table shows only the Ashton row. Click on it. Now, clear the text from the Search field. Ashton is selected, but Tiger is not.

When I click a row, I need to be able to act on any arbitrary row in the table, whether it is shown in the table or not. In this case, I need to be able to toggle on a class in a row that may not be there because it's not in the Search filter's results.

Is there an internal representation of the table that I can access, so that I can properly toggle the selected state of a row that is not shown during a search (filter)? I assume there is one, otherwise the table could not be reconstituted when a filter is cleared. But I'm not clear on how to access it.

Let me know if you have any questions on the above.

Thanks!

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 20,269Questions: 26Answers: 4,765
    edited July 2021 Answer ✓

    Thanks for the test case and detailed description. Helps a lot!

    Is there an internal representation of the table that I can access

    The only rows in the DOM are those being displayed. You can use rows().nodes() to get all the rows. You can pass your jQuery selector into the rows() API as the row-selector to filter the rows returned. For example:
    https://jsfiddle.net/1jeu82b3/

    Kevin

  • suttsutt Posts: 10Questions: 1Answers: 0

    Wow, thank you for the quick response, Kevin!

    I was able to show this solution working in a forked version of that previous example:

    https://jsfiddle.net/kx5cq3yj/

    My actual situation is slightly different, but I think I have everything I need to be able to implement the fix with this API.

    I really appreciate your help. And I'm glad the rows() API exists!

Sign In or Register to comment.