Filament 3 - Columns in export do not match the specified order
I'm using Filament 3 ver v3.3.14 and have an export column like this :
class SiteProgressExporter extends Exporter
{
protected static ?string $model = TargetProductProgress::class;
public function getFileName(Export $export): string
{
return 'Site Progress-' . date('YmdHis');
}
public function getFormats(): array
{
return [
ExportFormat::Xlsx,
];
}
public static function getTableQuery(): Builder
{
return parent::getTableQuery()
->with([
'target',
'target.vendor',
'target.province',
'target.city',
'target.type',
'communication',
'product',
'material',
'progress_status',
]);
}
public static function getColumns(): array
{
return [
ExportColumn::make('target.name')
->label('Site Name'),
ExportColumn::make('period_start')
->label('Period Start'),
ExportColumn::make('period_end')
->label('Period End'),
ExportColumn::make('target.vendor.name')
->label('Vendor'),
ExportColumn::make('target.province.name')
->label('Province'),
ExportColumn::make('target.city.name')
->label('City'),
ExportColumn::make('communication.name')
->label('Communication'),
ExportColumn::make('target.type.name')
->label('Type'),
ExportColumn::make('product.name')
->label('Product'),
ExportColumn::make('material.name')
->label('Material'),
ExportColumn::make('target.latitude')
->label('Latitude'),
ExportColumn::make('target.longitude')
->label('Longitude'),
ExportColumn::make('progress_status.name')
->label('Status'),
ExportColumn::make('created_at')
->label('Created'),
ExportColumn::make('progress')
->label('Progress')
->getStateUsing(function ($record): string {
return progress_percentage(
$record->progress_true_count,
$record->progress_count
);
}),
];
}
public static function getCompletedNotificationBody(Export $export): string
{
$body = 'Your site progress export has completed and ' . number_format($export->successful_rows) . ' ' . str('row')->plural($export->successful_rows) . ' exported.';
if ($failedRowsCount = $export->getFailedRowsCount()) {
$body .= ' ' . number_format($failedRowsCount) . ' ' . str('row')->plural($failedRowsCount) . ' failed to export.';
}
return $body;
}
}
but the result look like this : https://ibb.co.com/N22KVcyx
I want to set columns :
Site Name | Period Start | Period End | Vendor | Province | City | Communication | Type | Product | Material | Latitude | Longitude | Status | Created | Progress
The result :
Site Name | Vendor | Province | City | Type | Latitude | Longitude | Period Start | Period End | Communication | Product | Material | Status | Created | Progress
It look like the export sorts the columns in the relationships first before sorting the columns in the current table. How to fix this code?
I have cleared the cache and filament.
Please or to participate in this conversation.