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

Fixes #6361 (refs #5987).

Bug

`filterRowModelFromRoot` discarded sub-rows when the parent passed the filter but recursion was skipped because `depth >= maxLeafRowFilterDepth`. The parent row was pushed into `flatRows` and `rowsById`, but the children stayed reachable only via `row.subRows`, leaving `flatRows` an incomplete view of the visible tree.

`column.getFacetedUniqueValues()` (which iterates `flatRows`) returned consistent counts before filtering but inconsistent counts after, because the pre-filter `flatRows` from the core row model includes sub-rows while the filtered `flatRows` did not.

Fix

Add a small helper `addSubRowsToFlatArrays` that recursively pushes each surviving sub-row into `flatRows` and `rowsById`, and call it from the `else if` branch the parent-pass / depth-skipped case falls into. The branch is reached only when `row.subRows.length` is truthy, so the helper always has work to do.

`flatRows` and `rowsById` now contain the same set of rows that `rows` plus the surviving `row.subRows` paths cover, so faceted-unique counts and other flat-row consumers agree with the visible tree.

`filterRowModelFromLeafs` already pushed every passing leaf (including sub-rows that came from recursion) into `flatRows` via its own loop, so the bug was specific to `filterRowModelFromRoot`.

Tests

Local test harness is not available in this environment (no `node_modules`), but the change is small and the cases are mechanical:

scenariobeforeafter
no filterflatRows = all rowsflatRows = all rows
maxLeafRowFilterDepth = 100, normal filterflatRows = passing rows at all depthsunchanged
maxLeafRowFilterDepth = 0, parent passesflatRows = [parent only]flatRows = [parent + subRows]
maxLeafRowFilterDepth = 0, parent passes, sub-rows also have subRowssubRows of subRows missingincluded recursively

A follow-up commit can add a regression test once the test harness is wired up locally; happy to do that in response to review feedback.

1 file changed, +20/-0.

Summary by CodeRabbit

  • Bug Fixes
    • Improved filtered table results so nested rows stay consistent in the visible row list and row lookup data, even when filtering depth limits are reached.
    1. Review Change Stack

      No actionable comments were generated in the recent review. 🎉

      ℹ️ Recent review info
      ⚙️ Run configuration

      Configuration used: defaults

      Review profile: CHILL

      Plan: Pro

      Run ID: 90310c85-ffa8-445f-aa15-823a25204ae5

      📥 Commits

      Reviewing files that changed from the base of the PR and between 9db621f3c5a3086152933992dd9f0c29c6bbf828 and b6352cc5c407b10a2f9c8e4718c50ff69ca89fe6.

      📒 Files selected for processing (1)
      • packages/table-core/src/features/column-filtering/filterRowsUtils.ts

      📝 Walkthrough

      Walkthrough

      Adds a recursive helper addSubRowsToFlatArrays in filterRowModelFromRoot that mirrors a passing row's sub-rows into flatRows and rowsById when recursion is halted by maxLeafRowFilterDepth, fixing inconsistency between row.subRows and the flattened row representation.

      Changes

      flatRows Consistency Fix

      Layer / File(s)Summary
      Add flatRows mirroring helper
      packages/table-core/src/features/column-filtering/filterRowsUtils.ts
      Adds addSubRowsToFlatArrays helper that recursively appends sub-rows into newFilteredFlatRows/newFilteredRowsById, and invokes it in the filtering recursion when a passing row's depth reaches maxDepth but still has subRows.

      Estimated code review effort: 2 (Simple) | ~10 minutes

      🚥 Pre-merge checks | ✅ 5
      ✅ Passed checks (5 passed)
      Check nameStatusExplanation
      Description Check✅ PassedCheck skipped - CodeRabbit’s high-level summary is enabled.
      Title check✅ PassedThe title clearly summarizes the main fix for column filtering and flatRows behavior at maxLeafRowFilterDepth.
      Linked Issues check✅ PassedThe change matches issue #6361 by adding skipped sub-rows to flatRows and rowsById when recursion stops at max depth.
      Out of Scope Changes check✅ PassedThe diff stays focused on the filtering bug fix and does not introduce unrelated changes.
      Docstring Coverage✅ PassedNo functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
      ✨ Finishing Touches
      🧪 Generate unit tests (beta)
      • Create PR with unit tests

      Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

      ❤️ Share
      Comment `@coderabbitai help` to get the list of available commands.
    2. KevinVandy closed this

Sign in to join this conversation.