export excel with serial number

Hello, I want to add new Filament\Actions\Exports\ExportColumn field in my exporter that should display serial number of the records in excel. My current code which prints 1 for every record, it isnt incrementing: public static function getColumns(): array { $rowNumber = 1; return [ ExportColumn::make('serial_number') ->label('SN.') ->state(function () use (&$rowNumber): string { return $rowNumber++; }), ExportColumn::make('name'), ]; }
1 Reply
toeknee
toeknee6d ago
It wouldn't know to increment. You would need do it on the row count on the class, so
protected int $rowNumber = 1;
protected int $rowNumber = 1;
then
public static function getColumns(): array
{
return [
ExportColumn::make('serial_number')
->label('SN.')
->state(fn () => $this->rowNumber++),
ExportColumn::make('name'),
];
}
public static function getColumns(): array
{
return [
ExportColumn::make('serial_number')
->label('SN.')
->state(fn () => $this->rowNumber++),
ExportColumn::make('name'),
];
}
Want results from more Discord servers?
Add your server