F
Filament2y ago
Remi

Detect of sortable has been turn on or off on column

I want to do different things based on if a sort on a column has been turned on or off.
TextColumn::make('first_name')->sortable(),
TextColumn::make('first_name')->sortable(),
if the column is sorted either asc or desc, i want to update a bool variable to true on the Livewire component, if the sort is in its idle state, it want to update the variable to false. Is there a way for me to detect this? The docs describe this callback, but cant figure out if there is an "on" and "off" option to detect?
->sortable(query: function (Builder $query, string $direction): Builder {
return $query
->orderBy('last_name', $direction)
->orderBy('first_name', $direction);
})
->sortable(query: function (Builder $query, string $direction): Builder {
return $query
->orderBy('last_name', $direction)
->orderBy('first_name', $direction);
})
2 Replies
Dan Harrin
Dan Harrin2y ago
maybe try $this->tableSortColumn and $this->tableSortDirection for the current sorting state
Remi
RemiOP2y ago
Perfect! thanks, that does the job!
Want results from more Discord servers?
Add your server