question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Expandable + Filterable Table: subRows empty after a filter was set

See original GitHub issue

Describe the bug (required) A clear and concise description of what the bug is. When using a table with the useFilters and useExpand plugins, the subRows of a row with children is empty after setting a filter and clearing it again.

Provide an example via Codesandbox! (required) https://codesandbox.io/s/runtime-currying-odrn8?file=/src/App.js

Steps To Reproduce (required)

  1. Open the provided code sandbox
  2. expand the first row (optional), just to make sure there are subRows
  3. Filter the second column (Visits) to 29
  4. Remove the filter from the second column (Visits) again
  5. The first row doesn’t have subRows any longer

Expected behavior (Recommended) I would expect that I can see the original subrows of each row after removing all filters

Screenshots If applicable, add screenshots to help explain your problem. ReactTableError

Desktop (please complete the following information):

  • OS: MacOS Catalina 10.15.4
  • Browser: Chrome
  • Version: 81.0.4044.138

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:5
  • Comments:7

github_iconTop GitHub Comments

1reaction
jalajguptacommented, Jan 20, 2021

@matveychuk Can you please provide me an codesandbox example and is global filter working in SubRows as well?

0reactions
matveychukcommented, Jan 6, 2021

I solved it by adding custom filter function to filterTypes

  const filterTypes = React.useMemo(
    () => ({
      filterRowsWithSubrows: (rows, id, filterValue) => {
        return rows.filter((row) => {
          const rowValue = row.values[id];
          return rowValue !== undefined ? String(rowValue).toLowerCase() === String(filterValue).toLowerCase() : true;
        });
      },
    }),
    [],
  );

and then add filterTypes to useTable hook

const tableInstance = useTable(
    {	
      columns
      data,
      filterTypes,
    },
    useFilters
)

and then add this custom filter to column as a string name “filterRowsWithSubrows” for value “filter”

export const status = {
  Header: 'Status',
  accessor: 'status',
  filter: 'filterRowsWithSubrows',
  Filter: SelectColumnFilter,
};
Read more comments on GitHub >

github_iconTop Results From Across the Web

subRows empty after a filter was set · Issue #2309 · TanStack ...
When using a table with the useFilters and useExpand plugins, the subRows of a row with children is empty after setting a filter...
Read more >
Filters | TanStack Table Docs
The ability for a column to be column filtered is determined by the following: The column was defined with a valid accessorKey /...
Read more >
Filter Nested Tables before Expanding in Power Query
If you're an avid Power Query user you'll often need to filter nested tables before you expand them in Power Query. In this...
Read more >
Examples • reactable - GitHub Pages
The table search method can be customized using the searchMethod argument in reactable() . See the Custom Filtering guide for details and examples....
Read more >
How to group rows in Excel to collapse and expand them
I'm trying to figure out how to group rows, but so that when filtering, Excel considers the grouped rows together and just uses...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found