Skip to content

How to expand to first found leaf or expand all when filtering #5703

Closed Answered by chattling
chattling asked this question in Q&A
Discussion options

You must be logged in to vote

I found the solution. First I debounced filter value to improve performance. Then I added logic to globalFilterFn, if the filter match, I get all the parent rows (those are the expandable rows), and if they not yet expanded, I expand each:

  const table = useReactTable({
    data: tasks,
    columns,
    state: {
      globalFilter: debounceGlobalFilter,
    },
    getSubRows: (row) => row.subRows,
    getCoreRowModel: getCoreRowModel(),
    getExpandedRowModel: getExpandedRowModel(),
    getFilteredRowModel: getFilteredRowModel(),
    onGlobalFilterChange: setGlobalFilter,
    globalFilterFn: (row, columnId, filterValue) => {
      if (row.getValue(columnId).toLowerCase().includes(filter…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by chattling
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant