Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

filterFromLeafRows table option does not work #4190

Closed
2 tasks done
marcaltmann opened this issue Jul 20, 2022 · 5 comments
Closed
2 tasks done

filterFromLeafRows table option does not work #4190

marcaltmann opened this issue Jul 20, 2022 · 5 comments

Comments

@marcaltmann
Copy link

Describe the bug

The filterFromLeafRows table option seems to not work properly. It is filtering out way more rows than expected.

I used the React Table Expanding example (https://tanstack.com/table/v8/docs/examples/react/expanding) and modfified it, setting the option filterFromLeafRows on the table.

Now when filtering, it seems that the filter value must match both the sub row and the parent row in order for the rows to remain visible. If the filter value matches only the sub row, nothing is displayed (maybe an AND where an OR is needed?).

Your minimal, reproducible example

https://codesandbox.io/s/compassionate-gates-0bpvhg

Steps to reproduce

  1. Expand the first row in the table, e.g. in my case the row "Jalon"
  2. In the filter of the first column, enter what you see in one of the sub rows (e.g. the name "Bonnie")

Expected behavior

As a user, I expect the row "Bonnie" as well as its parent "Jalon" to remain.
Instead, both rows will disappear.

How often does this bug happen?

Every time

Screenshots or Videos

No response

Platform

Linux, Firefox

react-table version

v8.2.6

TypeScript version

No response

Additional context

No response

Terms & Code of Conduct

  • I agree to follow this project's Code of Conduct
  • I understand that if my bug cannot be reliable reproduced in a debuggable environment, it will probably not be fixed and this issue may even be closed.
@rizwanliaqat97
Copy link

I'm facing same problem, currently worked around it by my own filter function

@marcaltmann
Copy link
Author

I tried using a custom filter function, but it did not help. How did you do it?

@rizwanliaqat97
Copy link

In my case I had many level of subrows, (i.e a subrow could contain more subrows) so even if one subrow matched any level I had to show the the parent rows, I have recurssive function but that's just for my need as I can't tell how many levels deep I'll go, depends on the data.

So what my filter function does is it checks the data of current row and returns true if it matches, and then it also looks into subrow data (because subrow data is also part of parent row data), if any subrow matches, it still returns true for parent row

Something like this: (It's simplified, I had a recussive function for my subrows)

(row, colId, filterValue) => {
    if (current_row_matches) {
      return true;
    }

    // If the row doesn't match then add this row to result only if one of its child rows match
    if (check_if_this_row_has_subrows) {
      const subrowData = row.subrows;

      // go through subrow data to find a match (`Array.some()` is very handy here)
     const matchFound = subrowData.some(subrow => check_if_this_subrow_matches);

     if(matchFound) {
        return true;
        }
    }

    // if nor the current row neither any of its subrows matched, exclude this row from result
    return false;
  };

@rek
Copy link
Contributor

rek commented Sep 9, 2022

I also have this issue when using filterFromLeafRows and expanded. Anyone have a custom working getFilteredRowModel we can use in the meantime?

@kasunnirmala
Copy link

Same issue here. Not filtering leaf elements though that flag is enabled.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants