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 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(), because 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' =>...
1 Reply
Josh777
Josh777OP2d ago
Bumping this 👀

Did you find this page helpful?