0

I have created a REST controller for a custom entity that should be administrated by the backend of the Sulu CMS. My implementation is analog to this example.

Now I want to define a default sorting at the list view. Currently the items are listed just like they are fetched from the database. Of course the user can sort it in the frontend.

But I want to order the list per default by the entities name attribute.

stollr
  • 6,534
  • 4
  • 43
  • 59

1 Answers1

1

If you are using the listBuilder with fieldDescriptors you can do something like this:

$fieldDescriptors = $this->fieldDescriptorFactory->getFieldDescriptors('your_list');

// ....

if (!$request->query->get('sortBy')) { // set default sorting when no sorting is given
    $listBuilder->sort($fieldDescriptors['created'], 'desc');
}
Alexander Schranz
  • 2,154
  • 2
  • 25
  • 42