Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

pre selecting in mui datagrid disables the data grid

I have a mui datagrid which i want to have preselected rows. this is my code

`

 const movieCrewList = movieCrew.map((item) => item.id);
 const [selecteTabledData, setSelectedTableData] = React.useState([]);
 <DataGrid
rows={crewData}
columns={columns}
pageSize={5}
rowsPerPageOptions={[5]}
checkboxSelection
onSelectionModelChange={(selectionModel) => {
setSelectedTableData(selectionModel);
}}
selectionModel={movieCrewList}
/>

`

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

it works and I get the pre selected rows but the problem is I cant select any other rows after that and it looks like the whole table gets disabled.

>Solution :

use selecteTabledData in the selectionModel

  selectionModel={selecteTabledData}

use useEffect to set the default value in the state

const [selecteTabledData, setSelectedTableData] = React.useState([]);

useEffect(() => {
    const movieCrewList = movieCrew.map((item) => item.id);
    setSelectedTableData(movieCrewList)
}, [movieCrew])
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading