To implement row selection (via checkbox or row click), use the TableSelection utility to manage state. When handling row clicks, use isWithinInteractiveElement to ensure clicking a button or checkbox inside a row doesn't trigger the row's selection logic.
const [data] = useState(['Amsterdam', 'Berlin', 'Limassol', 'Prague'])
const [selection, setSelection] = useState(() => new TableSelection<string>({data}))
return (
<Table
data={data}
getKey={(_, i) => i}
columns={[
{
key: 'Check',
renderCell: item => (
<input
type="checkbox"
checked={selection.isSelected(item)}
onChange={e => setSelection(
e.target.checked
? selection.select(item)
: selection.deselect(item)
)}
/>
)
},
{
key: 'City',
renderCell: item => item,
}
]}
renderItem={(item, index, items) => (
<DefaultItemRenderer
index={index}
clickable
selected={selection.isSelected(item)}
onClick={e => {
if (!isWithinInteractiveElement(e.target)) {
setSelection(selection.toggleSelection(item))
}
}}
/>
)}
/>
)