-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Array index as an accessorKey in ColumnDef does not work #4815
Comments
Hi buddy, your accessorKey type is incorrect. Just change it to a string. |
Hi! That is my point. The linked documentation says integers are fine: https://tanstack.com/table/v8/docs/guide/column-defs#array-indices So either the documentation is wrong or the code is wrong. And I mentioned the type of the key under "Additional context" in my original post. |
This is still an issue. Additionally, when using the |
Unfortunately, the issue still persists. I fixed it using an accessor function: columnHelper.accessor((row) => row[0], { ... }) But it would be great if the maintainers update the documentation to help others avoid running into this bug |
Describe the bug
The TanStack documentation describes that you can use array indices as the
accessorKey
value if your data is in the form of nested arrays: https://tanstack.com/table/v8/docs/guide/column-defs#array-indicesHowever, if you do that, the library will crash when rendering the table.
Your minimal, reproducible example
https://codesandbox.io/s/hungry-breeze-50qbjx
Steps to reproduce
Create a table by calling
useReactTable
set the data to nested arrays, and use numbers as the accessorKeys. Below is a React component that reproduces it:Expected behavior
The table renders normally and does not crash.
How often does this bug happen?
Every time
Screenshots or Videos
No response
Platform
Windows 11, Chrome 112.0.5615.121
react-table version
8.8.5
TypeScript version
No response
Additional context
As a workaround you can make a string out of the number, and the table works as expected. I.e. the following works fine:
Terms & Code of Conduct
The text was updated successfully, but these errors were encountered: