How to set row(s) as selected based on rowData value?
I'm using material-table for a work project, and am wondering if it's possible to set row(s) as selected automatically based on a particular column of the data?
In my application I have an edit screen with a material-table of servers with the selection feature enabled. One of the columns called 'Related' is either true or false. I need the rows in which Related === true to automatically be selected, and those in which Related === false to be un-selected.
I can't post my code because it's against company policy, but I don't really think it's necessary here.
Has anyone already done this? Or is it possible?
Pass this options object to the table
options={{
selection: true,
selectionProps: (rowData) => ({
checked: <your logic here>},
}),
}}
Thanks @s-kris!
That works for checking rows where Related === true, but it doesn't allow me to uncheck those rows afterwards. In this use case I also want allow them to uncheck the rows that are checked, which would then set Related === false.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. You can reopen it if it required.