© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•10mo ago•
2 replies
Josh777

Refresh widget method `getOptions()` after filtering

I posted this on Github last week, but haven't had any response: https://github.com/filamentphp/filament/discussions/16111

I have filters on my Chart Widget like this:

protected function getFilters(): ?array
{
    return [
        'today' => 'Today',
        'week' => 'Last week',
        'month' => 'Last month',
        'year' => 'This year',
    ];
}
protected function getFilters(): ?array
{
    return [
        'today' => 'Today',
        'week' => 'Last week',
        'month' => 'Last month',
        'year' => 'This year',
    ];
}


Upon select of one of these options, i want to change the min and max values in the y axis using the
getOptions
getOptions
method.

protected function getOptions(): RawJs
{
    $min = array_rand(range(0, 100), 1);
    $max = array_rand(range(100, 200), 1);
    
    $js = RawJs::make(<<<'JS'
        {
            scales: {
                y: {
                    ticks: {
                        callback: (value) => '£' + value,
                    },
                    min: %min%,
                    max: %max%,
                },
            },
        }
    JS);

    $js = str_replace('%min%', $min, $js);
    $js = str_replace('%max%', $max, $js);

    return RawJs::make($js);
}
protected function getOptions(): RawJs
{
    $min = array_rand(range(0, 100), 1);
    $max = array_rand(range(100, 200), 1);
    
    $js = RawJs::make(<<<'JS'
        {
            scales: {
                y: {
                    ticks: {
                        callback: (value) => '£' + value,
                    },
                    min: %min%,
                    max: %max%,
                },
            },
        }
    JS);

    $js = str_replace('%min%', $min, $js);
    $js = str_replace('%max%', $max, $js);

    return RawJs::make($js);
}


If i do this and change the filter options, the min and max values don't change (even though I am using
array_rand()
array_rand()
, because
getOptions
getOptions
only renders once. Upon changing filter I need to somehow refresh the method/component/widget so that the random values (in this example) actually change. If you try this with a chart widget you will see they stay the same.

How can I fix this?
GitHub
Refresh widget method `getOptions()` after filtering · filamentphp...
I have filters on my Chart Widget like this: protected function getFilters(): ?array { return [ 'today' => 'Today', 'week' => 'Last week', 'month' =>...
Refresh widget method `getOptions()` after filtering · filamentphp...
Filament banner
FilamentJoin
A powerful open source UI framework for Laravel • Build and ship admin panels & apps fast with Livewire
20,307Members
Resources
Was this page helpful?

Similar Threads

Recent Announcements

Similar Threads

Refresh Dashboard Widget
FilamentFFilament / ❓┊help
9mo ago
refresh table widget after tab button changed
FilamentFFilament / ❓┊help
16mo ago
Refresh Table after performed action in Widget
FilamentFFilament / ❓┊help
2y ago
Create custom filtering widget
FilamentFFilament / ❓┊help
2y ago