Sort List view by two columns #1262
-
Hello, I have an Order List view, which I am sorting by the Order Ship By date as follows:
This works great, but orders with the same ship_by_date do not get ordered by the id or the created_date. I want to do the following:
Unfortunately, this does not work. Any ideas on how to get the sorting by two columns to work? With Regards, |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
To sort the List view by two columns in Backpack, you can use the if (!$this->crud->getRequest()->has('order')) {
$this->crud->addClause('orderBy', 'ship_by_date', 'asc');
$this->crud->addClause('orderBy', 'id', 'asc');
} This approach uses the The reason for using This solution is based on the information provided in the Backpack CRUD How-To documentation and the Backpack CRUD List Operation documentation. Remember to place this code in your If you need further customization or if this doesn't solve your specific use case, you might need to override the ℹ️ Please note our AI Bot does not reply to follow-ups, this will be the only AI answer in this thread. If the AI helped you find the answer, please mark it as answered or write details below so it can learn. Then close the conversation. If not, please give more information for when a human reads this. ℹ️ Relevant sources: Github Issue (closed): [Bug] Multi column order doesn't work |
Beta Was this translation helpful? Give feedback.
To sort the List view by two columns in Backpack, you can use the
orderBy
method multiple times. However, the way you're trying to chain theorderBy
methods won't work directly. Instead, you can modify your approach slightly to achieve the desired result. Here's how you can sort by bothship_by_date
andid
:This approach uses the
addClause
method to add multiple ordering clauses to the query. It will first sort byship_by_date
in ascending order, and then byid
in ascending order for entries with the sameship_by_date
.The reas…