Jump to:

3433 Posts in 1058 Topics by 734 members

Data Model Questions

SilverStripe Forums » Data Model Questions » [Solved] Customising results in Model Admin

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

Page: 1
Go to End
Author Topic: 661 Views
  • cumquat
    Avatar
    Community Member
    191 Posts

    [Solved] Customising results in Model Admin Link to this post

    Hi there,

    Not sure if this is a bug or if this function needs changing for 3.1 I am using the function below to filter out some records displayed in model admin as per the example on the reference page.

    public function getList() {
    $list = parent::getList();
    // Always limit by model class, in case you're managing multiple
    if($this->modelClass == 'Producer') {
    $list->exclude('New', '0');
    }
    return $list;
    }


    This used to work in version 3.0.2 but with 3.1 beta 3 its just not working any more. Any pointers?

    Mick

  • kinglozzer
    Avatar
    Community Member
    138 Posts

    Re: [Solved] Customising results in Model Admin Link to this post

    Hi cumquat. DataLists are now immutable, meaning you'll need to do this:

    public function getList() {
    $list = parent::getList();
    // Always limit by model class, in case you're managing multiple
    if($this->modelClass == 'Producer') {
    $list = $list->exclude('New', '0');
    }
    return $list;
    }

    Note the "$list = " addition.

  • cumquat
    Avatar
    Community Member
    191 Posts

    Re: [Solved] Customising results in Model Admin Link to this post

    Thanks for this, I saw it mention immutable eventually in the change log but had no idea what that meant.
    Will give this a go when I get home.

    Thanks again

    Mick
    ##Update##
    All working, cheers for that.

  • James Bolitho
    Avatar
    Community Member
    33 Posts

    Re: [Solved] Customising results in Model Admin Link to this post

    I was trying to figure out what was going on for a while when getting 'GridFieldPaginator expects an SS_Limitable' error then saw this post.

    Just to add to the solution above I found that when using the filters I needed to add a couple of checks for empty values when using a dropdown field for example with an empty value as the default value, i.e. when resetting the filters in Model Admin etc.

    public function getList() {
    if($this->modelClass == 'Product'){
          $list = parent::getList();
    $params = $this->request->requestVar('q');
    if(isset($params['Status']) && $params['Status'] != null || $params['Status'] != '') $list = 'whatever filter/query you are using';
    return $list;
    }

    Hope this helps others too.

    Many Thanks,
    James.

    661 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.