react-virtualized icon indicating copy to clipboard operation
react-virtualized copied to clipboard

[Table] Pass rowData instead of just index for cases like onRowClick

Open yhware opened this issue 9 years ago • 3 comments

So I'm making a pretty standard datatable using the Table component. All was good until I implemented row selection, sorting and filtering. Sorting and filtering by themselves is not a problem but as soon as row selection comes into play, I must be able to keep track of the "primary key" of the row, not the relative index of the row in the table. For simple selection, I implemented this by changing the "defaultRowRenderer" to the following

if (onRowClick) { a11yProps.onClick = () => { onRowClick({ index, rowData }) } }

So now I can get the rowData every time I click on the row. But the problem is, I also need to display which rows are selected to the users even after a filter has been applied and the "rowStyle" prop only provides the relative index of the row, not the rowData. I believe this little tweak can reduce great amount of housekeeping code people need to write to keep the relative row number and the actual primary key of the row in sync for the aforementioned case etc.

yhware avatar Dec 31 '16 05:12 yhware

Ok so just to update others, I managed to mark which rows are selected by adding a custom className to the custom version of defaultRowRenderer like the following

if(rowData.selected){ className += " RV_ROW_SELECTED" }

then using css to highlight selected rows

yhware avatar Dec 31 '16 18:12 yhware

Hi @yhware,

Would you like to contribute a PR that adds the rowData parameter to the defaultRowRenderer? I would support this change. 😄

bvaughn avatar Dec 31 '16 21:12 bvaughn

Nevermind. Closed via 449717a. This will go out with the next release at some point.

bvaughn avatar Jan 01 '17 19:01 bvaughn