kwatman
kwatman
Explore posts from servers
FFilament
Created by kwatman on 10/5/2024 in #❓┊help
Show a navigation item for each type entry that exists
Hello in my app i have a location model. the location model has a relation with a type model. when i click on the locations navigation item i want a sub navigation to open where i can select which type of location i want to see. so if i have a type of town and city. i want two navigation items to appear. a town and a city navigation item. when clicking one of them i want it to show a table with either all locations of type town or city. depending in which one you clicked. is there a way to do this in filament ?
2 replies
FFilament
Created by kwatman on 6/26/2024 in #❓┊help
Exporting a sorted sum column with ExportAction
Im trying to export a list of users with a sum column. im my table for users i added this:
TextColumn::make('rides_sum_distance')
->label('Total distance')
->sum('rides', 'distance')
->default(0)
->formatStateUsing(fn (string $state): string => number_format($state, 2, ',', '.') . ' km')
->sortable()
->badge()
TextColumn::make('rides_sum_distance')
->label('Total distance')
->sum('rides', 'distance')
->default(0)
->formatStateUsing(fn (string $state): string => number_format($state, 2, ',', '.') . ' km')
->sortable()
->badge()
The get colums method for the exporter looks like this:
public static function getColumns(): array
{
return [
ExportColumn::make('id')
->label('ID'),
ExportColumn::make('name'),
ExportColumn::make('email'),
ExportColumn::make('created_at'),
ExportColumn::make('rides_sum_distance')
->sum('rides', 'distance')
->default(0)
->formatStateUsing(fn (string $state): string => number_format($state, 2, ',', '.') . ' km '),
];
}
public static function getColumns(): array
{
return [
ExportColumn::make('id')
->label('ID'),
ExportColumn::make('name'),
ExportColumn::make('email'),
ExportColumn::make('created_at'),
ExportColumn::make('rides_sum_distance')
->sum('rides', 'distance')
->default(0)
->formatStateUsing(fn (string $state): string => number_format($state, 2, ',', '.') . ' km '),
];
}
this all works. the table shows the sum correctly and i can export it. however when i sort the table on the rides_sum_distance i get the following error for the PrepareCsvExport job:
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'rides_sum_distance' in 'order clause' (Connection: mysql, SQL: select distinct * from `users` order by `rides_sum_distance` desc limit 100 offset 0)
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'rides_sum_distance' in 'order clause' (Connection: mysql, SQL: select distinct * from `users` order by `rides_sum_distance` desc limit 100 offset 0)
It seems like the moment a sort is added the export looks for the colomn in the database. Is there any way to prevent this ?
13 replies