when I click in the checkbox of the table row, I am updating the array selecteddata with id and after that I am passing the checked value by finding whether id exists in the selecteddata to check the checkbox. I am able to store the id in selectedData but it is not showing instance changes in checkbox.
const [selectedData, setSeletcedData] = useState([]);
const handleCheckboxSelect = (id) => {
setHasSelectedAll(false);
setSeletcedData((selectedData) => {
if (selectedData.includes(id)) {
return selectedData.filter((currentId) => id !== currentId);
} else {
selectedData.push(id);
return selectedData;
}
});
};
<CDataTable
items={matter}
fields={fields}
hover
pagination
count: (item) => (
<CFormGroup variant="checkbox" className="checkbox">
<CInputCheckbox
id="checkbox1"
name="checkbox1"
value="option1"
checked={selectedData.includes(item.id)}
onChange={(e) => handleCheckboxSelect(item.id)}
/>
</CFormGroup>
),
}}
/>