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.

1 Answer 1

2

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');
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.