pxlrbt / filament-excel

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

Table header action now extends Filament\Actions\Action #132

Closed Michael-HEIW closed 8 months ago

Michael-HEIW commented 8 months ago

Following the documentation for Actions\Tables\ExportAction for table header actions, this now throws an exception in Filament v3

use pxlrbt\FilamentExcel\Actions\Tables\ExportAction;

// ...

    protected function getHeaderActions(): array
    {
        return [
            ExportAction::make()->exports([
                ExcelExport::make('table')->fromTable(),
            ])
        ];
    }

// ....

This now throws an exception:

InvalidArgumentException
PHP 8.2.9
10.29.0
Header actions must be an instance of Filament\Actions\Action, or Filament\Actions\ActionGroup.

The fix is to update pxlrbt/filament-excel/src/Actions/Tables/ExportAction.php

- use Filament\Tables\Actions\Action;
+ use Filament\Actions\Action; 

The export action then works as expected.

buzkall commented 8 months ago

The merged PR #133 breaks the code if you're adding a header option directly to the table function in the resource like this

->headerActions([
      ExportAction::make()->exports( [
              ExcelExport::make()->fromTable()
      ])
])

with version 2.1.7 throws exception "Method pxlrbt\FilamentExcel\Actions\Tables\ExportAction::table does not exist." with version 2.1.6 works

saulens22 commented 8 months ago

Yes, it seems to be broken.

getHeaderActions() is a method used for pages, so pxlrbt\FilamentExcel\Actions\Pages\ExportAction should be used.

pxlrbt\FilamentExcel\Actions\Tables\ExportAction should be only used like this:

return $table
  ->columns([...])
  ->headerActions([
      \pxlrbt\FilamentExcel\Actions\Tables\ExportAction::make('myexportaction')->exports([
          // export logic
      ]),
  ]);

Pull request #133 should be reverted.

pxlrbt commented 8 months ago

Thanks for confirming. I just reverted the PR.

pxlrbt commented 8 months ago

@saulens22 Thanks for pointing out that the wrong Action was used.

Michael-HEIW commented 8 months ago

Sorry for the problem, that was not my intension.

I tried the return $table->headerAction it worked perfect.