I have implemented a Table using the react-virtualized Table component. I have added a checkbox column in the table and now want to implement the select all/select row functionality using those checkboxes.
Now, for adding select all/select row functionality, I am using react hooks for changing the checked prop of CheckBox but it doesn't seem to work. Below is the code link and when I scroll down the page with actual data, the checkbox checked state is removed.
Here's the code that I am trying to do, checked is always remaining false for rows except for the header. Header select all is functioning fine
...
import {Checkbox} from 'semantic-ui-react';
const[selectAll, setSelectAll] = useState(false):
const checked = [];
function _checkboxState(data) {
if (checked.includes(data.index)) {
checked.pop(data.index);
} else {
checked.push(data.index);
}
}
<Column
disableSort
dataKey="checkbox"
width={30}
headerRenderer={() => (
<Checkbox
checked={selectAll}
onChange={() => {
if (selectAll === true) {
setSelectAll(false);
} else {
setSelectAll(true);
}
}}
/>
)}
cellRenderer={({rowIndex}) => (
<Checkbox
checked={selectAll || checked.includes(rowIndex)}
onChange={(e, data) => {
_checkboxState(data);
}}
index={rowIndex}
/>
)}
/>
...
- How to maintain the checks after even scrolling the table?
- Where I am doing wrong for checking individual rows?
Any help on this is appreciated!