Jump to:

3431 Posts in 1058 Topics by 734 members

Data Model Questions

SilverStripe Forums » Data Model Questions » ModelAdmin sort and sort direction

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 3679 Views
  • bmc38119
    Avatar
    Community Member
    45 Posts

    ModelAdmin sort and sort direction Link to this post

    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'
    );

    }
    ?>

  • bmc38119
    Avatar
    Community Member
    45 Posts

    Re: ModelAdmin sort and sort direction Link to this post

    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.

  • Ingo
    Avatar
    Forum Moderator
    801 Posts

    Re: ModelAdmin sort and sort direction Link to this post

    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.

  • Fuzz10
    Avatar
    Community Member
    787 Posts

    Re: ModelAdmin sort and sort direction Link to this post

    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 ?

  • Ingo
    Avatar
    Forum Moderator
    801 Posts

    Re: ModelAdmin sort and sort direction Link to this post

    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

    3679 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.