Toggle selected table row

Can I use getTableRecordAction to toggle the selected row?
E.g on click of the row if check/unchecks the selection checkbox.

Only way I've found to do this is by adding this to every column
->extraCellAttributes(fn ($record) => ['x-on:click' => "areRecordsSelected([{$record->id}]) ? deselectRecords([{$record->id}]) : selectRecords([{$record->id}])"])


Ideally, I'd like to do it like this:
protected function getTableRecordActionUsing(): ?\Closure
{
    return fn ($recordKey): string => "areRecordsSelected([{$recordKey}]) ? deselectRecords([{$recordKey}]) : selectRecords([{$recordKey}])";
}
Was this page helpful?