Homepage
Main navigation
Main content
Additional information
Login / Sign up
Quality Guidelines
About
GitHub
Propose new content
Winter CMS resources and help articles
Simple and to the point. Optimized by the community.
×
Login / Sign up
Quality Guidelines
About
GitHub
Propose new content
Edit trick
Changes will be published after manual review
Title
Give your trick a describing title. Do
not
start with «How to...».
Your trick
Keep it short and concise! Markdown is supported.
Add the following code in your backend controller class to apply a default sort configuration to your list based on the value selected in a given filter scope: ```php public function listFilterExtendScopes(Filter $filterWidget) { $getSortConfig = function (Filter $filter) { $currentStatus = $filter->getScopeValue('status') ?? $filter->scopes['status']['default']; $defaultSorts = [ 'upcoming' => [ 'column' => 'start_date', 'direction' => 'asc', ], 'completed' => [ 'column' => 'start_date', 'direction' => 'desc', ], ]; return $defaultSorts[$currentStatus]; }; // Apply default sort column / direction logic based on the selected status filter $this->listGetWidget()->defaultSort = $getSortConfig($filterWidget); // Apply default sort config when updating the status filter $filterWidget->bindEvent('filter.update', function () use ($filterWidget, $getSortConfig) { if (post('scopeName') === 'status') { $sort = $getSortConfig($filterWidget); $this->listGetWidget()->setSort($sort['column'], $sort['direction']); } }, 1); } ```
References
Add additional online resources to your trick
×
Name
URL
+ Add reference
Topics
If your trick fits more than one topic select multiple. Select at least one.
Backend
Plugin Development
CMS
Twig
Themes
Deployment
Tags
You can use existing tags or create new ones. Add at least one.
Submit for review
Cancel
We use cookies to measure the performance of this website. Do you want to accept these cookies?
Accept
Decline