$default_sort not working

**Silverstripe Version:4.11

Any idea why private static $default_sort = 'DeadLineDate DESC'; doesn’t work?

The initial code was private static $default_sort ='SortOrder';

Has anything changed regarding the $default_sort?

Thanks in advance.

You will hardly have any answer if you don’t provide a shred of information. What “doesn’t work” means in this context? What’s the code that “does not work”?

Has anything changed regarding the $default_sort?

No, it hasn’t.

I am sorry, I thought it is clear that I expected to get the list of DeadLineDate sorted in a descending order which doesn’t work. I still get them in the order of the SortOrder id. I even tried to sort them descending using the SortOrder

$default_sort = 'SortOrder DESC';

which doesn’t work.
Is this code above wrong?

I assume your $default_sort is being set inside some subclass of DataObject and that DeadLineDate is a $db property on that class?

Where are you expecting this sort to be seen? On the frontend? In a GridField in the CMS? What is the code you are using the get and to display the records?

Hi Guy,
Thanks for your response.

Yes, it is in a class:

class DeadLine extends DataObject {
      .private static $db = 
           ['DeadLineDate' => 'Date',
           'SortOrder' => 'Int'

and I expect this to be seen in the admin area of that page where I use it using GridField:

$fields->addFieldToTab('Root.Dealines', GridField::create('Deadlines', 'Deadline', $this->Deadlines(), GridFieldConfig_RecordEditor::create()->addComponent(new GridFieldSortableRows('SortOrder'))));

It looks like the GridFieldSortableRows component will adjust the DataList to keep sorting on SortOrder rather than DeadLineDate. If you no longer need the SortOrder column then just try removing the ->addComponent(new GridFieldSortableRows('SortOrder')).

Thanks a lot, kaftka. That was it :grinning:.