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 /

[Solved] Customising results in Model Admin


Reply


4 Posts   826 Views

Avatar
cumquat

Community Member, 198 Posts

1 May 2013 at 9:06pm

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

Avatar
kinglozzer

Community Member, 171 Posts

2 May 2013 at 4:16am

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.

Avatar
cumquat

Community Member, 198 Posts

2 May 2013 at 4:27am

Edited: 05/05/2013 6:37am

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.

Avatar
James Bolitho

Community Member, 33 Posts

28 September 2013 at 12:13am

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.