pxlrbt / filament-excel

Excel Export for Filament Admin Resources
MIT License
323 stars 68 forks source link

How to add custom column? #136

Closed Umar-Farooq-Shafi closed 8 months ago

Umar-Farooq-Shafi commented 8 months ago

I want to add some custom columns in the export. e.g

    public function setUp(): void
    {
            $types = Option::query()
                ->where('type', OPTION_TYPE::EMT_PROCEDURE())
                ->get();

            foreach ($types as $type) {
                $columns[] = Column::make($type->name)
                    ->heading($type->name)
                    ->formatStateUsing(function (Model $record) use ($type) {
                        if (str_contains($record->procedure, $type->name)) {
                            return '1';
                        }

                        return '0';
                    });
            }

            $this->withColumns($columns);
    }
pxlrbt commented 8 months ago

And what's the issue? Maybe you need ->getStateUsing() instead of ->formatStateUsing()

talhachughtai123 commented 8 months ago

@Umar-Farooq-Shafi Did you find solution?

pxlrbt commented 8 months ago

@talhachughtai123 Did you try the proposed solution?!

Umar-Farooq-Shafi commented 8 months ago

yes, thanks for the help. @pxlrbt

talhachughtai123 commented 8 months ago

Please tell me the solution

Umar-Farooq-Shafi commented 8 months ago

And what's the issue? Maybe you need ->getStateUsing() instead of ->formatStateUsing()

as @pxlrbt suggested.