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-indices
However, 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:
const Table =() => {
const table = useReactTable({
data: [
['Hello', 1, 2, 3],
['World', 4, 5, 6],
],
columns: [
{ header: 'Name', accessorKey: 0 },
{ header: 'Col1', accessorKey: 1 },
{ header: 'Col2', accessorKey: 2 },
{ header: 'Col3', accessorKey: 3 },
],
getCoreRowModel: getCoreRowModel(),
});
return (
<table>
<thead>
<tr>
{table.getFlatHeaders().map((header) => (
<th key={header.id}>
{header.isPlaceholder
? null
: flexRender(header.column.columnDef.header, header.getContext())}
</th>
))}
</tr>
</thead>
<tbody>
{table.getRowModel().rows.map((row) => (
<tr key={row.id}>
{row.getVisibleCells().map((cell) => (
<td key={cell.id}>{flexRender(cell.column.columnDef.cell, cell.getContext())}</td>
))}
</tr>
))}
</tbody>
</table>
);
});
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:
columns: [
{ header: 'Name', accessorKey: '0' },
{ header: 'Col1', accessorKey: '1' },
{ header: 'Col2', accessorKey: '2' },
{ header: 'Col3', accessorKey: '3' }
]
Terms & Code of Conduct
Describe the bug
The TanStack documentation describes that you can use array indices as the
accessorKeyvalue 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
useReactTableset 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