Skip to content

Sorting on Anonymous columns? #2023

Answered by lrljoe
mallanza asked this question in Q&A
Discussion options

You must be logged in to vote

Absolutely, you can use a callback in "sortable"

e.g. sorting by "amount_invoice"

Column::make('DPM')
  ->label(fn ($row, Column $column) =>
  (($row->total_mileage>0 || $row->other_mileage>0) && $row->amount_invoice>0) ? $row->amount_invoice / ($row->total_mileage + $row->other_mileage) : 0)
    ->sortable(
        fn(Builder $query, string $direction) => $query->orderBy('amount_invoice', $direction)
    ),

Replies: 1 comment

Comment options

lrljoe
Oct 30, 2024
Collaborator Sponsor

You must be logged in to vote
0 replies
Answer selected by mallanza
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants