react-data-grid
react-data-grid copied to clipboard
Pass rowIdx in Row to Cell and column formatter
Use case
I'm trying to add a column which shows row number. But there is no way currently. Currently I have to check the complete rows array and get the row index. This can be expensive for large number of rows.
Proposed solution
If the rowIdx prop of Row is passed to the Cell component and forwarded to column formatter, I can use the rowIdx to show the row number. If required, I can raise the PR.
Even passing rowIdx to onRowClick can be helpful to get the selected cell position.
@amanmahajan7 @nstepien The commit - https://github.com/adazzle/react-data-grid/commit/905074a0a4c171a8847703182ec923a618da1bec has broken the working of having Context as suggested in #2844. It is not working anymore. How to pass extra data to Row formatters now ?
I am overriding the default SelectColumn with my own checkbox, but my implementation requires a unique id. It would be really convenient if I could get access to the output of rowKeyGetter or the rowIdx. The data in my table is customer generated and dynamic, so I don't know what fields exist on each row, so I am unable to know what (if any) datapoints are unique on the row.
For now, the only thing I can think of is to modify the data in advance to add in my own rowIdx to the dataset, which is not ideal.