I have added an editable react-table (https://codesandbox.io/s/github/tannerlinsley/react-table/tree/master/examples/kitchen-sink) to my project and everything works fine. But when I added a column with checkboxes, and tick the checkboxes and go to a different page (or sort or search) and come back, ticks are gone. This is how I have added the checkbox to the 'columns' field,
{
Header: 'On Leave',
accessor: 'onLeave',
Filter: SelectColumnFilter,
filter: 'includes',
disableGroupBy: true,
Cell: row => { return(
<div style={{'text-align':'center'}}>
<input type="checkbox"
value={row.value == "Yes" ? "on" : "off"}
onBlur={(event) => updateMyData(parseInt(row.row.id), row.column.id, event.target.checked ? "Yes" : "No")} />
</div>)},
}
updateMyData() is fired when focus is lost from checkbox and console.log prints correct data,
0 : 0 : onLeave : Yes
1 : 1 : onLeave : Yes
2 : 2 : onLeave : Yes
3 : 3 : onLeave : Yes
4 : 4 : onLeave : Yes
updateMyData() is as follows,
// When our cell renderer calls updateMyData, we'll use
// the rowIndex, columnId and new value to update the
// original data
const updateMyData = (rowIndex, columnId, value) => {
// We also turn on the flag to not reset the page
skipResetRef.current = true
setData(old =>
old.map((row, index) => {
if (index === rowIndex) { console.log(index + " : " + rowIndex + " : " + columnId + " : " + value););
return {
...row,
[columnId]: value,
}
}
return row
})
)
}
Why is the checkbox values not saved in 'data' field? Thanks