gregnb / gregnb/mui-datatables
How can I make a checkbox checked as default when data has selected item
- Dominant language
- JavaScript
- Stars
- 2.7k
- Forks
- 906
- PR merge metrics
- No merged PRs in 30d
Description
Hello,
I would like to know how I get in a row a checkbox already checked when I have specific data.
I'm receiving data as `preparedSites[dataIndex][0] === site.siteId` as you will see under when I have this condition true I'm putting the row with a background color.
On the same row, the box should be already checked but I don't know how to do it.
I hope to get some help with it :)
Thank you
```
const options = useMemo(
() => ({
filter: true,
filterType: 'dropdown',
responsive: 'standard',
tableBodyHeight: '100%',
tableBodyWith: '100%',
tableBodyMaxHeight: '100%',
selectableRowsHideCheckboxes: hideCheckBox,
selectableRowsOnClick: true,
selectableRows: 'single',
search: false,
viewColumns: false,
download: false,
print: false,
isRowSelectable: dataIndex => preparedSites[dataIndex][5] !== 'INACTIVE',
setRowProps: (row, dataIndex) => {
if (preparedSites[dataIndex][0] === site.siteId)
return {
style: { backgroundColor: 'rgba(0, 168, 238, .1)' },
};
else if (preparedSites[dataIndex][5] === 'INACTIVE')
return {
style: {
opacity: '.5',
},
};
return '';
},
setFilterChipProps: () => {
return {
color: 'primary',
variant: 'outlined',
};
},
onRowSelectionChange: rowsSelectedData => {
const id = preparedSites[rowsSelectedData[0].dataIndex][0];
const status = preparedSites[rowsSelectedData[0].dataIndex][5];
if (status === 'ACTIVE') selectSite(id);
},
}),
[sites, site],
);
```
Contributor guide
No contributing guide indexed for this repository
Research direction
Review the selectableRows, selectableRowsOnClick, isRowSelectable, and onRowSelectionChange options shown in the issue. Compare them with the project's selectable-row documentation or examples, and confirm the supported way to initialize the row matching preparedSites[dataIndex][0] === site.siteId as checked while keeping selection callbacks consistent.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, react
- Domain
- frontend
- Issue type
- Documentation
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100