T
TanStack2y ago
quickest-silver

row index

Hi every one. I want to add row index to table in columns array. How can i do that? { id: 'index', header: 'index', cell: ({ row }) => { return <span>{?}</span>; }, indexed: true, enableSorting: false, enableHiding: false, },
1 Reply
fascinating-indigo
fascinating-indigo10mo ago
Hey! Did you have any luck with this? My situation is similar – I want to autoFocus on an input in a cell, but only if the row is the last rendered row in the table (accounting for sort) in the accessor's cell I can use table.getRowCount() to know what the current row's index should be, but row.index is the index of the row in the original data array, not sorted row.id appears to be the same as row.index, based on the original data order I feel like I could probably use table.getRowModel() and then findIndex of the row with index = this row's row.index but I worry that getRowModel() is expensive to call once per rendered row... Here's where I'm leaving my solution for the moment because done is better than perfect, but if folks who know more about table performance than I do have a better solution I'd love to hear!
cell: ({ row, table }) => (
<MyComboboxComponent
data={row.original}
isLastRow={table.getRowCount() === table.getRowModel().rows.findIndex((checkRow) => checkRow.index === row.rowIndex) + 1}
/>
),
cell: ({ row, table }) => (
<MyComboboxComponent
data={row.original}
isLastRow={table.getRowCount() === table.getRowModel().rows.findIndex((checkRow) => checkRow.index === row.rowIndex) + 1}
/>
),

Did you find this page helpful?