F
Filament4mo 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),
]);
}
}
<?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
]);
}
}
<?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
]);
}
}
3 Replies
elabx
elabxOP4mo ago
so the issue was I removed the widget inclusion on getFooterWidgets() and rolled them back to include them in the panel provider, then it worked, is this expected behavior? ok so continuing on this issue, it seems that specifically the table widget is not getting filtered automatically, so will keep working on that, but that's a different issue 🙂
NickBell
NickBell3w ago
I've been stuck with the same issue. Did you ever resolve this? Looks like the InteractsWithPageFilters concern is intended for StatsWidgets only... I can't quite make sense of what's going on with it
elabx
elabxOP2w ago
@NickBell sorry for the ultra late reply, i think what was missing is making sure these were configured in the AdminPanelProvider

Did you find this page helpful?