Closed pqr closed 3 years ago
How would you like it to look? I'm not sure if we need a default property, but we can add one.
Now this can be done using a filter:
/**
* @param Builder $builder
*
* @return Builder
*/
public function run(Builder $builder): Builder
{
return $builder->defaultSort('id')
}
We could add default filters, like the trash filter.
For example:
$builder->defaultSort($builder->getModel()->getKeyName(), 'asc');
// or
$builder->defaultSort($builder->getModel()->getKeyName(), 'desc');
This will automatically match the primary keys and will not be visually displayed in any way.
And adding to the resource will look like this:
/**
* Get the filters available for the resource.
*
* @return array
*/
public function filters(): array
{
return [
RoleFilter::class,
DefaultSortDesc::class
];
}
What do you think about this?
I thought about following options:
$defaultSortColmn
and $defaultSortOrder
properties on Resouce classpublic function defaultSortColumn(): string
and defaultSortOrder()
on Resource classFor my current situation option 1 (new props) would be enough.
Regarding your proposal about adding filter witch manipulates with $builder
- it sounds like "option 3"!
The only doubt that I fill "Filter" semantically is something that filters out records, but not sorting them, not changing the order.
Unfortunately, these modifiers are already named as Filters. Using them will give you a lot more flexibility than simple properties.
I tried my own version, and it may not always fit, since I want to indicate the column, maybe?
public function filters(): array
{
return [
new DefaultSorted('id', 'asc'),
];
}
I've just used in my project - works as expected! Thanks!
I am looking for a method to set default sorting column in CRUD. I need some option or method inside Resource class to define default sort column.
This is how it works in "classic" list screen: https://orchid.software/en/docs/quickstart-sort-filter-table/