iTwin / iTwinUI-react

A react component library for iTwinUI.
https://github.com/iTwin/iTwinUI
Other
83 stars 23 forks source link

Table: Property for Auto selection of row #721

Closed vsnandanwar closed 1 year ago

vsnandanwar commented 2 years ago

Feature

Currently, I am not able to select any row automatically. There is a provision to disable a particular row at the time of rendering. It will be good if the same type of provision is also there to select a row in order to show the check box as checked.

Examples

I want something like this where I will be able to select/check any row at the time of rendering through props

image

veekeys commented 2 years ago

Hello @vsnandanwar

Have you tried to use initialState prop to pass selected rows? Something like

<Table ... initialState={{selectedRowIds: {rowId1: true, rowId2: true}}}

You can read docs for more info https://react-table-v7.tanstack.com/docs/api/useRowSelect#table-options

vsnandanwar commented 2 years ago

I tried using this, but for this, I should know the ids of the rows. In my case, I need to do some logic to find out the rows to be selected and then set them as checked. So, Is there anything where I can update the row as checked?

veekeys commented 2 years ago

@vsnandanwar I am not sure I understand the question. You do not even know what rows you want to have selected initially? For the id, you can easily define that yourself, by passing getRowId function, which has a default react-table implementation (mostly ends up with index of the row). Have a look at it in here https://react-table-v7.tanstack.com/docs/api/useTable#table-options

image

veekeys commented 1 year ago

@vsnandanwar as there is no activity here, hope the suggestions helped to achieve what you want. I am closing this issue. Feel free to open a new one or reopen this if you still face some issues.