F
Filament2mo ago
John

Can dashboard page react to filters?

Hello, I am currently building a custom dashboard that has filter, with use HasFiltersForm; and have added some simple toggle buttons to the filter ("today", "last 7 days", "last 30 days"). that sort of thing. The widgets are reacting with the filter with the use of use InteractsWithPageFilters; However i want to display some basic text to let the user know the date period that they selected. Since the dashboard has no blade file (that I know of), is there anywhere I can hook this information? besides putting them on individual widget itself which will clutter it with dates. Currently what I did was adding it to the filtersForm method, however the data is not 'reactive' its working, but it is lagging behind Here's my code
public function filtersForm(Schema $schema): Schema
{
$dates = DateFilterService::getStartAndEndDateByFilter($this->filters['quickFilters']);
$selectedPeriod = $dates['startDate'] . ' to ' . $dates['endDate'];

return $schema
->components([
ToggleButtons::make('quickFilters')
->label('')
->inline()
->options([
'latest' => 'Latest',
'last7days' => 'Last 7 Days',
'last30days' => 'Last 30 Days',
'prevmonth' => 'Previous Month',
])
->default('latest')
->columnSpan(2),
Text::make("Selected Period {$selectedPeriod}")
->columnSpanFull(),

]);
}
public function filtersForm(Schema $schema): Schema
{
$dates = DateFilterService::getStartAndEndDateByFilter($this->filters['quickFilters']);
$selectedPeriod = $dates['startDate'] . ' to ' . $dates['endDate'];

return $schema
->components([
ToggleButtons::make('quickFilters')
->label('')
->inline()
->options([
'latest' => 'Latest',
'last7days' => 'Last 7 Days',
'last30days' => 'Last 30 Days',
'prevmonth' => 'Previous Month',
])
->default('latest')
->columnSpan(2),
Text::make("Selected Period {$selectedPeriod}")
->columnSpanFull(),

]);
}
2 Replies
Harvey
Harvey2mo ago
The Text::make() won't update because filtersForm likely isn't re-rendered. You should instead use a callback like so:
Text::make(function (self $livewire) {
return "Filter is " . $livewire->filters['quickFilters'] ?? 'Default';
})
->columnSpanFull(),
Text::make(function (self $livewire) {
return "Filter is " . $livewire->filters['quickFilters'] ?? 'Default';
})
->columnSpanFull(),
However i want to display some basic text to let the user know the date period that they selected. Since the dashboard has no blade file (that I know of), is there anywhere I can hook this information? besides putting them on individual widget itself which will clutter it with dates.
I'm not an expert but you could have your own custom dashboard view file. It's looks to be just a basic page with the following:
<x-filament-panels::page>
{{ $this->content }}
</x-filament-panels::page>
<x-filament-panels::page>
{{ $this->content }}
</x-filament-panels::page>
You could then put a banner at the top or something and you can access the Dashboard livewire component like usual. If you could tell where the perfect place for the date message to go, it might spark an idea.
John
JohnOP2mo ago
Thanks. I'll give it a try

Did you find this page helpful?