If I click the full checkbox button, then all other checkboxes should be ticked. If all checkboxes are ticked and I remove one tick, then the full checkbox should be unticked along with the checkbox we unticked. Help to resolve. I am using Kendo React code. This is my code
1
The answer will depend on your implementation, but general function can be written as follows:-
const handleSelectAllCheckboxChange = (e) => {
const isChecked = e.target.checked;
setIsSelectAll(isChecked);
if(isChecked) {
setSelectedArr(list)
} else {
setSelectedArr([])
}
};
const handleCheckboxChange = (listIndex, e) => {
const elemInd = selectedArr.findIndex((item) => item === list[listIndex]);
if(elemInd === -1) {
setSelectedArr([...selectedArr, list[listIndex]]);
if(selectedArr.length === list.length - 1) {
setIsSelectAll(true)
}
} else {
setSelectedArr(selectedArr.splice(elemInd, 1));
setIsSelectAll(false)
}
};