Default Filter Value for Filterable Fields #5845
-
|
Filters support the concept of default values, but filterable fields do not. I would like to propose the following syntax: Select::make('Status')->filterable(default: 'active');
Select::make('Status')->filterable(null, 'active');
Select::make('Status')->filterable()->filterableDefault('active');This is actually very easy to implement in the source code. On the Filterable trait, you can make the following modifications:
public function filterable(?callable $filterableCallback = null, mixed $filterableDefault = null)
{
/* ... */
$this->filterableDefault = $filterableDefault;
}As well as add the direct mutator: public function filterableDefault(mixed $filterableDefault)
{
$this->filterableDefault = $filterableDefault;
}Then, in the Field Filter, override the
public function default()
{
return $this->field->filterableDefault;
}The workaround without this feature is to fully define a custom filter, which feels like overkill for such a small change. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
|
While we wait for the Nova team to add this, we can address the situation using this excellent package: https://novapackages.com/packages/javii-script/default-value-filterable |
Beta Was this translation helpful? Give feedback.
While we wait for the Nova team to add this, we can address the situation using this excellent package:
https://novapackages.com/packages/javii-script/default-value-filterable