Skip to content
Source
Sign inSign up
TanStack/table

getFacetedRowModel inconsistently respects maxLeafRowFilterDepth: 0 #5987

Send to my agent
ClosedMark-Triffin(GitHub profile, opens in a new tab) opened this issue 0 comments

TanStack Table version

v8.20.6

Framework/Library version

v18.3.1

Describe the bug and the steps to reproduce it

Hi,

I have the following setup for the table:

const table = useReactTable({
    data,
    columns,
    getRowId: (row, _, parent) => (parent ? [parent.original._id, row._id].join(".") : row._id),
    getCoreRowModel: getCoreRowModel(),
    getFilteredRowModel: getFilteredRowModel(),
    getFacetedRowModel: getFacetedRowModel(),
    getFacetedUniqueValues: getFacetedUniqueValues(),
    getSubRows: (row) => row?.products?.flatMap((p: { product: TProduct }) => (p?.product?.name ? [p.product] : [])),
    columnResizeMode: "onChange",
    autoResetPageIndex: false,
    maxLeafRowFilterDepth: 0,
  });

And elsewhere I have components for filtering that use table.getColumn("columnName")?.getFacetedUniqueValues() in order to show the amount of items that will be filters.

I've found then before any filtering is applied the facet counts include all items at every level of the array that match, but after a filter is applied only the items at the top of the tree are counted (even though all items still show due to the maxLeafRowFilterDepth: 0). This seems incorrect.

My hope is that the getFacetedUniqueValues could support maxLeafRowFilterDepth. However, even if not I believe that consistency between before and after filtering is important.

https://codesandbox.io/p/devbox/charming-bush-lcnqhz

Screenshots or Videos (Optional)

No response

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

None

Terms & Code of Conduct

  • I agree to follow this project's Code of Conduct
  • I understand that if my bug cannot be reliable reproduced in a debuggable environment, it will probably not be fixed and this issue may even be closed.
  1. KevinVandy closed this

Sign in to join this conversation.