TanStackT
TanStack4y ago
3 replies
uncertain-scarlet

Add extra function to onchange of indeterminate checkbox

Hi guys, I have a question about the v8 Row Selection example for React:
In that example a custom component IndeterminateCheckbox is created and then used as the cell value for the columns:
            <IndeterminateCheckbox
              {...{
                checked: row.getIsSelected(),
                indeterminate: row.getIsSomeSelected(),
                onChange: row.getToggleSelectedHandler(),
              }}
            />


This works great, but I would like to add extra functionality to the onChange, I have tried to begin simple and changed the code to:
            <IndeterminateCheckbox
              {...{
                checked: row.getIsSelected(),
                indeterminate: row.getIsSomeSelected(),
                onChange: () => {row.getToggleSelectedHandler(); console.log(row.original.SomeInformationFromData)},
              }}
            />


Now the console.log() does work and does print the data as expected, however, the selection does not work anymore!
Not visual and not in the state either (I printed it, but am getting an empty array)

Does anyone have any idea how I can add an extra function to the onChange without breaking the row.getToggleSelectedHandler()
Was this page helpful?