Skip to content

Expanding rows on filtering #1159

Discussion options

You must be logged in to vote

I found a solution!

` useEffect(() => {
const expandedRows = table.getRowModel().rows.map(row => row.id)

if (table.getState().globalFilter === undefined || '') {
  table.setExpanded(
    [rootNode[0]?.uuid, selectedNode.parent_id].reduce((accum, id) => ({ ...accum, [id]: true }), {})
  )
} else {
  table.setExpanded(expandedRows.reduce((accum, id) => ({ ...accum, [id]: true }), {}))
}

}, [table.getState().globalFilter])`

! in the IF condition, we hide the nested table elements (in my case, the main parent element of the table is revealed) when we clear the search (global filter).

in the ELSE condition, we expand the table when we search for something in the search (global filter).

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by BorisChubiryaev
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