table icon indicating copy to clipboard operation
table copied to clipboard

Unable to access Map entries with array keys by value in getFacetedUniqueValues function

Open gabrielcosi opened this issue 1 year ago • 2 comments

TanStack Table version

8.12.0

Framework/Library version

NextJS v14.0.4

Describe the bug and the steps to reproduce it

I've encountered an issue when using the getFacetedUniqueValues function to retrieve the faceted unique values for a column in a table. The problem arises when the column value is an array and I attempt to access the corresponding facet using the array value as the key.

Your Minimal, Reproducible Example - (Sandbox Highly Recommended)

https://stackblitz.com/edit/tanstack-table-stfatx?file=src%2Fmain.tsx

Screenshots or Videos (Optional)

Status: Shows the number of entries for each option CleanShot 2024-03-13 at 00 33 21@2x

Labels: Nothing due to it being an array CleanShot 2024-03-13 at 00 34 56@2x

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

None

Terms & Code of Conduct

  • [X] I agree to follow this project's Code of Conduct
  • [X] 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.

gabrielcosi avatar Mar 13 '24 05:03 gabrielcosi

Hi, any solution on this ? I am facing the same

zacBkh avatar Jul 16 '24 09:07 zacBkh

a fix that worked for me is adding getUniqueValues to the columns object related to that array column, for example i have a tags column that has an array of objects with id,name,color

getUniqueValues: (row) => {
      const res = row.tags ? row.tags.map(t => t.id.toString()) : []
      return res
}

this seems to show the correct number of rows for each tag

not that my facets filter component uses getFacetedUniqueValues to fill that variable.

Flowko avatar Jul 21 '24 13:07 Flowko