I’m now using shadcn datatable with Tanstack table.
I have checkbox on first column, but confused how to check all the checkboxes as default.
And also have to select / deselect when click on checkbox on header, so defaultChecked
property may not work in this case.
This is my checkbox column definition:
{
id: 'select',
header: ({ table }) => {
dataTable.value = table
return h(Checkbox, {
'checked': table.getIsAllRowsSelected() || (table.getIsSomeRowsSelected() && 'indeterminate'),
'onUpdate:checked': (value) => {
table.toggleAllRowsSelected(!!value)
},
'ariaLabel': 'Select all',
})
},
cell: ({ table, row }) => h(Checkbox, {
'checked': row.getIsSelected(),
'onUpdate:checked': (value) => {
row.toggleSelected(!!value)row.original.meter)
},
'ariaLabel': 'Select row',
}),
enableSorting: false,
enableHiding: false,
},
Is there a hook that I can call table.toggleAllRowsSelected()
to select all, or how can I make this work?
Thanks!