Hey all! I’m trying to allow a user to select a row, however that is done I am not sure. I tried using OnClick but given the available props for TableRow it doesn’t work.
Anyone have got this working?
AI suggested wrapping in a <div> but that didn’t work
Hi @FOman, I hope that you are well!
Thanks for asking the Community!
Could you please share additional information such as what you are ultimately trying to achieve, the code used and where you are making the edits, to make sure that we help you the best we can?
The more info, screenshots (without sensitive/confidential information), and details you can provide, the better the Community can assist.
I’d like to invite a couple of subject matter experts to this conversation: Hi @Stephanie-OG, @Anonymous and @jeremymandle do you have suggestions to help @FOman, please?
Thanks a lot and have a great day!
Best,
Bérangère
Thanks Berangere! So here is more information, given a table, as shown below, I want a user ot be able to select a row, then it will display the selected ID. Specifically, I would like the row to change color, to show that it has been selected + change the state of a react useState variable, so I can use the selected ID in other places in the card.
I found a workaround which is to define each cell as a button so I can add the OnClick handler but it is far from ideal, and not user friendly at all. (the screenshot above shows the button implementation)
You can add an onClick event to your table rows. This will allow you to capture the click and take action. When you click on any row, the handleRowClick function will run with the data from that row.
Hi @FOman, thank you for the additional information!
Hi @GRajput, thanks a lot for your help!
Do you have insights to share with @FOman, please, regarding the 2 points above?
Have a lovely day and thanks a lot!
Best,
Bérangère