F
Filament16mo ago
HL

Set multiple columns in protected function getDefaultTableSortColumn()

Is it possible to order a table by multiple columns, just like:
$query->orderBy('col1', 'asc')->orderBy->('col2', 'asc')
$query->orderBy('col1', 'asc')->orderBy->('col2', 'asc')
?
3 Replies
HL
HL16mo ago
I've tried it based on this
HL
HL16mo ago
I managed to do it with the getTableQuery() function overwrite in the resource list:
protected function getTableQuery(): Builder
{
return static::getResource()::getEloquentQuery()->orderBy('col1', 'asc')->orderBy->('col2', 'desc');
}
protected function getTableQuery(): Builder
{
return static::getResource()::getEloquentQuery()->orderBy('col1', 'asc')->orderBy->('col2', 'desc');
}
The only issue with this is that I cannot use the ->sortable() on any of the columns, since this will overwire it anyways I found a github issue where you guys mentioned you'll introduce this featue in v3, looking forward to it! Let me know if there is a better solution though in v2
Dan Harrin
Dan Harrin16mo ago
i dont think there is a better solution atm