Skip to content

Sort List view by two columns #1262

Closed Answered by backpack-ai-bot bot
sharat-rhinofish asked this question in Q&A (Help)
Discussion options

You must be logged in to vote

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 the orderBy methods won't work directly. Instead, you can modify your approach slightly to achieve the desired result. Here's how you can sort by both ship_by_date and id:

if (!$this->crud->getRequest()->has('order')) {
    $this->crud->addClause('orderBy', 'ship_by_date', 'asc');
    $this->crud->addClause('orderBy', 'id', 'asc');
}

This approach uses the addClause method to add multiple ordering clauses to the query. It will first sort by ship_by_date in ascending order, and then by id in ascending order for entries with the same ship_by_date.

The reas…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by sharat-rhinofish
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
1 participant