Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add a default ordering of ListEntries table in Backpack for Laravel?

When a user first visits the page, the ListEntries table is ordered ascending by id and none of the ordering icons in the table header are active.

I would like to have the ListEntries table ordered by a column of my choosing, including having the icon next to this column active (either ascending or descending).

Is there a way to have the ListEntries table ordered by a column of my choosing when a user visits the page?

like image 880
Tiamo Idzenga Avatar asked Aug 31 '25 03:08

Tiamo Idzenga


1 Answers

In your Controller's setup() method you can use:

$this->crud->orderBy('name', 'DESC');

Anything you pass to the orderBy() statement will be used on the Eloquent query.

By default, columns for real attributes (that have a correspondent column in the database) should be orderable. But you can also manually specify 'orderable' => true for columns, or define your own order logic. Note that relationship columns (1-n, n-n), model_function or model_function columns are NOT orderable by default, but you can make them orderable with orderLogic.

Hope it helps.

like image 101
tabacitu Avatar answered Sep 03 '25 10:09

tabacitu