Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

nrdnisml's avatar

Filament Export Action Failed on Sorted Columns

I'm having trouble exporting to Excel using the native export action in Filament 3.2. When I sort the columns in the table and try to export to Excel, the process fails with the following error:

"PDOException: SQLSTATE[42P10]: Invalid column reference: 7 ERROR: SELECT DISTINCT ON expressions must match initial ORDER BY expressions LINE 1: select distinct on ("audit_findings"."id") * from "audit_fin..."

However, when I clear the sorting parameters, the export process succeeds.

0 likes
6 replies
jaseofspades88's avatar

Are you using native export functionality for Filament 3.2 and up? If you are, what do you have in your exporter class?

nrdnisml's avatar

@jaseofspades88 yes, just set up some columns in getColumns function, some columns are relationship columns for example :

protected static ?string $model = AuditFinding::class;
public static function getColumns(): array
    {
        return [
            ExportColumn::make('finding_ref_no'),
            ExportColumn::make('audit.audit_type')
                ->label('Audit Type'),
            ExportColumn::make('audit.audit_category')
                ->label('Audit Category'),
            ExportColumn::make('audit.audit_entity')
                ->label('Audit Entity'),
            ExportColumn::make('audit.project_name')
                ->label('Project Name'),
            ExportColumn::make('audit.project_code')
                ->label('Project Code'),
            ExportColumn::make('status'),
            ExportColumn::make('phase'),
            ExportColumn::make('auditee_position'),
            ExportColumn::make('auditee_department'),
            ExportColumn::make('finding_category'),
		    ExportColumn::make('auditAudiences.name as auditee')
                ->label('Auditee Name')
                ->getStateUsing(fn ($record) => 
								$record->auditAudiences
										->where('role', 'auditee')
										->pluck('name')),
		];
    }
nrdnisml's avatar

auditAudiences is a one to many relationship function between AuditFinding Model to AuditAudience Model

nrdnisml's avatar

@jaseofspades88 updated, and just use

->headerActions([
                ExportAction::make()->exporter(AuditFindingExporter::class)
                    ->fileDisk('public'),
            ])

at table function inside AuditFindingResource

nrdnisml's avatar
nrdnisml
OP
Best Answer
Level 1

Solved, just ignore the sorting params during export process with editing this line in vendor/filament/actions/src/Concerns/CanExportRecords.php > setUp()

// $query = $livewire->getFilteredSortedTableQuery();
$query = $livewire->getFilteredTableQuery();

Please or to participate in this conversation.