Skip to content
Source
Sign inSign up
TanStack/table

fix(column-filtering): include sub-rows in flatRows when maxLeafRowFilterDepth skips recursion #6395

Closedsanjibani(GitHub profile, opens in a new tab)wants to merge 1 commit intobeta fromrefs/pull/6395/headopened

Showing 1 changed file with 20 additions and 0 deletions.

x
0 of 1 viewed, 1 left
20 additions and 0 deletionspackages/table-core/src/features/column-filtering/filterRowsUtils.tsModified
View file
@@ -113,6 +113,20 @@
const newFilteredRowsById = makeObjectMap<Row<TFeatures, TData>>()
const maxDepth = table.options.maxLeafRowFilterDepth ?? 100
​
+ // Recursively flatten a row's sub-rows into flatRows and rowsById.
+ // Used when a parent row passes the filter but recursion past
+ // maxLeafRowFilterDepth was skipped, so sub-rows would otherwise be
+ // missing from the flattened representation.
+ const addSubRowsToFlatArrays = (row: Row<TFeatures, TData>) => {
+ for (const subRow of row.subRows) {
+ newFilteredFlatRows.push(subRow)
+ newFilteredRowsById[subRow.id] = subRow
+ if (subRow.subRows.length) {
+ addSubRowsToFlatArrays(subRow)
+ }
+ }
+ }
+​
// Filters top level and nested rows
const recurseFilterRows = (
rowsToFilter: Array<Row<TFeatures, TData>>,
@@ -139,6 +153,12 @@
newRow.subRows = recurseFilterRows(row.subRows, depth + 1)
row = newRow