How to Add Month Filter to FilamentPHP StatsOverviewWidget?

I am creating a custom StatsOverviewWidget in FilamentPHP to display monthly statistics. Currently, the widget displays data for the current month using Carbon to specify the date range. Now I want to make it more dynamic by adding a month filter so that users can switch between different time ranges such as "This Month" and "Last Month", or even specific months using the dropdown menu in the widget header. is that possible in filament StatsOverviewWidget?
6 Replies
zydnrbrn
zydnrbrn3w ago
i think you can try by adding custom action on the pages that set month to query params, and then adjust the query of widget data to use month data in the param if available
Code A
Code AOP2w ago
custom actions on the page? where is this? do you have any related articles or videos?
Code A
Code AOP2w ago
is it just adding getHeaderActions():? i tried adding this but the action doesn't want to appear the code is like this
class DoctorStatsOverview extends BaseWidget
{
protected function getHeaderActions(): array
{
return [
Action::make('edit')
->url(route('posts.edit', ['post' => $this->post])),
Action::make('delete')
->requiresConfirmation()
->action(fn () => $this->post->delete()),
];
}
class DoctorStatsOverview extends BaseWidget
{
protected function getHeaderActions(): array
{
return [
Action::make('edit')
->url(route('posts.edit', ['post' => $this->post])),
Action::make('delete')
->requiresConfirmation()
->action(fn () => $this->post->delete()),
];
}
zydnrbrn
zydnrbrn2w ago
yeah, i think positing the filter button on the header is a good way. btw the solution that i offer is by adding the action on the pages, not on the widget directly. But if you want to wrap the filter on the widget directly you can look at this: https://filamentphp.com/docs/3.x/actions/adding-an-action-to-a-livewire-component
Code A
Code AOP2w ago
Okay, I can do it, thanks for the information

Did you find this page helpful?