FilamentF
Filament6mo ago
elabx

page filters not working on table widget

I cannot get page filters to work on a custom dashboard page, I have this as the dashboard . My understanding is that I would only need to use the right traits HasFilterForm on the Dashboard class and InteractsWithPageFilters in the widget class, but $this->filters is always null in the widget query() method.

Thanks for further help! I feel I'm missing something very obvious but I'm new to laravel fillament this being my first project on the platform.

<?php

namespace App\Filament\Pages;

use App\Filament\Pages\AnalyticsDashboard\Widgets\UserIntentDistributionChart;
use App\Filament\Pages\AnalyticsDashboard\Widgets\AnalyticsTable;
use App\Models\SiteConfiguration;
use Filament\Forms\Components\DatePicker;
use Filament\Forms\Components\Select;
use Filament\Forms\Form;
use Filament\Pages\Dashboard as BaseDashboard;
use Filament\Forms\Components\Section;
use Filament\Forms\Get;

class AnalyticsDashboard extends BaseDashboard
{
    use BaseDashboard\Concerns\HasFiltersForm;
    protected static ?string $navigationIcon = 'heroicon-o-chart-bar';
    protected static ?string $navigationGroup = 'Analytics';
    protected static ?string $navigationLabel = 'Analytics Dashboard';

    protected function getHeaderWidgets(): array
    {
        return [];
    }

    public function getFooterWidgetsColumns(): int|string|array
    {
        return 3;
    }

    protected function getFooterWidgets(): array
    {
        return [
            UserIntentDistributionChart::
            AnalyticsTable::class,
        ];
    }

    public function filtersForm(Form $form): Form
    {
        return $form->schema([
            Section::make('Filters')
                ->schema([
                   // Forms schema
                ])
                ->columns(3),
        ]);
    }
}


And a table widget:
<?php

namespace App\Filament\Pages\AnalyticsDashboard\Widgets;

use App\Models\Analytics;
use Filament\Tables;
use Filament\Tables\Table;
use Filament\Widgets\TableWidget as BaseWidget;
use Barryvdh\Debugbar\Facades\Debugbar;
use Filament\Widgets\Concerns\InteractsWithPageFilters;

class AnalyticsTable extends BaseWidget
{
    use InteractsWithPageFilters;

    protected int | string | array $columnSpan = 'full';

    public function table(Table $table): Table
    {
        Debugbar::info($this->filters);

        return $table
        ->query(function () {
                $query = Analytics::query();


                // edit query...
                
                return $query;
            })
            ->columns([
                / columns
            ]);
    }
}
Was this page helpful?