TanStack / table

🤖 Headless UI for building powerful tables & datagrids for TS/JS - React-Table, Vue-Table, Solid-Table, Svelte-Table
https://tanstack.com/table
MIT License
25k stars 3.07k forks source link

Calling `row.getParentRow()` with expanded, filtered row models and initial filtering value throws an error #5630

Open Gascon1 opened 3 months ago

Gascon1 commented 3 months ago

TanStack Table version

v8.17.3

Framework/Library version

v18.3.0

Describe the bug and the steps to reproduce it

Calling row.getParentRow() inside a custom filter function for a given column throws an error (Cannot read properties of undefined (reading 'rows')) when using the expanded and filter row models.

I faced this issue when using a custom filter function that filters by both parent and child rows, allowing for multiple levels of nesting in the data staying visible if at least one item in the "family" matches the filter.

This issue does not happen when the initial filter value is empty, only when there's a defined initial filter value (see sandbox).

After hours of investigating I hit a dead end. From what I can see, one of the row models in the waterfall of row models called through filtering is unexpectedly returning undefined, but I couldn't make sense of why. My hunch is that it's the getPreSortedRowModel() call that causes the issue, but I've seen it fail at other row model calls as well.

Your Minimal, Reproducible Example - (Sandbox Highly Recommended)

https://codesandbox.io/p/devbox/tanstack-table-initial-filtering-error-qwf43v?file=%2Fsrc%2Fmain.tsx%3A121%2C48

Screenshots or Videos (Optional)

No response

Do you intend to try to help solve this bug with your own PR?

Maybe, I'll investigate and start debugging

Terms & Code of Conduct

etiennecoyacabelio commented 2 months ago

Any updates ? i'm facing the same issue