Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

Data Model Questions /

ModelAdmin sort and sort direction


Reply


5 Posts   3732 Views

Avatar
bmc38119

Community Member, 45 Posts

18 March 2009 at 4:46am

how can I declare the sort and sort direction on the ModelAdmin results?

here is my code for the DataObject.

<?php
class Contact extends DataObject {

static $db = array(
'ContactNameFirst' => 'Varchar(100)',
'ContactNameLast' => 'Varchar(100)',
    'ContactPhoneHome' => 'Varchar(100)',
    'ContactPhoneCell' => 'Varchar(100)',
    'ContactEmail' => 'Varchar(200)',
'ContactComment' => 'Text',
    'Referrer' => 'Varchar(200)'
);

static $searchable_fields = array(
'ContactNameFirst',
'ContactNameLast'
);

static $summary_fields = array(
'ContactNameFirst',
'ContactNameLast'
);

}
?>

Avatar
bmc38119

Community Member, 45 Posts

21 March 2009 at 5:37am

For anyone with the same question, since i just needed a single field sort, I modified the sort setting for this table in MySQL and this seemed to suit my needs.

Avatar
Ingo

Forum Moderator, 801 Posts

24 March 2009 at 12:55am

There's a DataObject::$default_sort property which gets applied whenever no sort parameter is explicitly passed. There's currently no way to specifiy this directly for ModelAdmin, but its on the cards for a more flexible tabular representation in the future.

Avatar
Fuzz10

Community Member, 787 Posts

1 May 2009 at 11:57pm

ModelAdmin sure look promising ! It is pretty basic at this stage , but I can definitely see the potential , great work !

Does anyone know if there is a way I can use a custom build column sort in the model-admin list ?

Avatar
Ingo

Forum Moderator, 801 Posts

7 May 2009 at 10:30am

You can use ModelAdmin::resultsTableClassName to customize the TableListField class being used for results. You can then create a subclass of it to provide custom functionality. If you just want different sorting, you can modify ModelAdmin->ResultsForm(), YourDataObject->getSearchContext(), or even just the default ordering through DataObject::$default_sort :)