I'm creating a file list with MUI DataGrid
. The user able to check the checkbox in DataGrid
to make their selection. I want the checkbox to reset after the user perform some action such as delete the selected file.
The problem I'm facing is after I perform the delete action, the checkbox are still checked in the same spot. For example before I press the delete button:
After I press the delete button:
The checkbox are still checked on the second row. How do I reset the checkbox programmatically?
const [selectedFile, setSelectedFile] = useState([]); // To keep selected file
const [files, setFiles] = useState([]); // To keep uploaded file
const deleteSelectedFile = () => {
const filteredFileList = files.filter(
(item) => !selectedFile.includes(item)
);
setFiles(filteredFileList);
};
<DataGrid
rows={displayFile ? displayFile : []}
columns={columns}
pageSize={3}
checkboxSelection
onSelectionModelChange={({ selectionModel }) =>
setSelectedFile(selectionModel)
}
/>