question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Provide a way to define a default ordering inside ListOperation

See original GitHub issue

Feature Request

What’s the feature you think Backpack should have?

A way to specify a default sort column for a list operation, eg.

Screen Shot 2022-02-09 at 5 05 11 PM

Have you already implemented a prototype solution, for your own project?

I’ve tried a couple methods but they don’t work, eg.

These don’t work at all for me, possibly because tables are too “sticky”. Even when I reset filters and manually set persistent-table=false in the URL, the last sorted column is always what’s sorted by. AJAX requests seem to always have order[0][column]: 1 and order[0][dir]: desc set.

I’ve even tried deleting my domain cookies and logging back in again to a “fresh” table, and it’s still sticky.

Even if these methods did work, they feel very hacky. For the first example especially, since we have to find the index of the column we want to sort by (we can’t reference it by name).


Do you see this as a core feature or an add-on?

Core.


Thanks. 🙏

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
tabacitucommented, Sep 27, 2022

I don’t think it’s properly documented, no. @pxpm could you please create a first draft for docs for this, and tag me to take a second look? 🙏

1reaction
pxpmcommented, Aug 29, 2022

Hello @joelmellon sorry for the time it took to get back here.

Usually column 0 it’s the model primary column that Backpack automatically adds when developer don’t manually specify it. By default, if you don’t apply any order to the table, Backpack will apply the “default order” that is primaryKey => DESC so that you get the last created items first.

You can change the order by applying your custom orders to any other columns, so Backpack will apply your orders first, and on top of that, the primary key order. You can also add your custom primary key orderBy, to override Backpack defaults.

The orderBy’s are applied on database level so they cannot be “model attributes”, but must be “table columns”.

The reset button does not reset query orders, only resets table orders/filters, so if you don’t apply any order, like I told you Backpack will apply the “orderBy primary key” in the query orders.

If in you controller you have something like:

public function setupListOperation() 
{
$this->crud->query->where('active', true)->orderBy('id', 'asc');
}

This is a query order, the reset button will not reset this order.

I hope I made myself clear enough here, so I will be closing this, let me know if I missed something so that I can re-open if needed.

Cheers

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to add a default ordering of ListEntries table in Backpack ...
In your Controller's setup() method you can use: $this->crud->orderBy('name', 'DESC');. Anything you pass to the orderBy() statement will be ...
Read more >
Default Sort of the records in list view - ServiceNow Community
Solved: I want to make default sort on "SortNum" column for all the user, how can we achieve that. @Ankur Bawiskar.
Read more >
List Operation :: 5.x Docs - Backpack for Laravel
Starting with Backpack v5.4 we have an easy way to disable both of those, in order to make the ListOperation super-fast on big...
Read more >
Default sorting order in data grid 2 | Mendix Forum
Hey, Is there a way to change the default sorting order in a datagrid 2. As a example: I have a datagrid 2...
Read more >
ListObjectsV2 - Amazon Simple Storage Service
Objects are returned sorted in an ascending order of the respective key names in the ... The owner field is not present in...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found