0

I'm using react material-table and and I was wondering if there's a way upon selecting table row to make other rows of the same table disabled. I'm using:

material-table selection: true 

I saw that there's a "onSelectionChange" but I couldn't make it work for my case.

2 Answers 2

1

Yes it is possible: First save the selected row in the state and return undefined, if a row is selected to remove the hover animation: onRowClick={!this.state.selectedRow ? ((evt, selectedRow) => this.setState({ selectedRow })): undefined}.

Additionally, you can override the rowStyle in options to grey out the text color to make the rows seem disabled:

options={{
         rowStyle: rowData => ({
            color: (this.state.selectedRow && this.state.selectedRow.tableData.id !== rowData.tableData.id) ? '#AAA' : '#000'
       })
}}

This will look like this before the click: enter image description here And like this after the click: enter image description here Of course, you can change the colors and behavior to your liking.

Here is a codesandbox to prevent of children, if a parent is selected. Does that help?

Sign up to request clarification or add additional context in comments.

1 Comment

Great example, but it doesn't seem to work because the options are rendered at first and it looks form tableData in the selectedRow which doesn't yet exist. From your example how can I disable all rows with Tipi= child(meaning selection(checkboxes) can't be checked) if a Tipi=adult is selected?
0

use disabled in jsx element like this:

`<td disabled={true} />`

or you can also make your own logic in curly braces, when it should be disabled!

Thanks!

1 Comment

Sorry, but this doesn't help me at all. MaterialTable doesn't use the element you've mentioned. The property is "disabled" as you've said, I just don't know how to integrate it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.