react-data-grid icon indicating copy to clipboard operation
react-data-grid copied to clipboard

Pass rowIdx in Row to Cell and column formatter

Open adityatoshniwal opened this issue 3 years ago • 2 comments

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.

adityatoshniwal avatar Nov 17 '21 10:11 adityatoshniwal

Even passing rowIdx to onRowClick can be helpful to get the selected cell position.

adityatoshniwal avatar Nov 18 '21 06:11 adityatoshniwal

@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 ?

adityatoshniwal avatar Sep 12 '22 10:09 adityatoshniwal

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.

paustint avatar Oct 22 '22 22:10 paustint