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.

Customising the CMS

[Solved] display set of results in gridfield


5 Posts   201 Views


14 July 2014 at 10:44pm Community Member, 52 Posts

Hi There

I would like my gridfield to list only results that match a value of a particular field eg if fieldvalue is <= some number only show these records?

i have looked around but can't find a solid answer to this can anyone help please?


15 July 2014 at 4:31am Community Member, 79 Posts

Would you mind sharing more details, code?


15 July 2014 at 9:05pm Community Member, 52 Posts

Can give more detail

there are 3 classes involved the firs is Client, in the client class there are 2 has_many relationships Quote and Archive.
These Display in tabs within the client.
Currently when you view the quote tab at present it lists all records and same for the archive tab
What i would like to do is when you view the quote tab is have it list only the quotes with a particular statusID, and the same for the archive tab when viewed.
both of these relationships are shown with gridfield and i do not want to delete any quotes as the archive gets in formation from the quote.
I have looked at using something in the gridfield config, also i have explored GridFieldConfig_RelationEditor to automatically detach any records with a particular statusID.

hope this helps and makes sense


15 July 2014 at 10:46pm Community Member, 79 Posts

Hi voodoochile

Below is sample gallery page which i created

class GalleryPage extends Page {

private static $has_many = array(
'GalleryImages' => 'GalleryImage',

//private static $icon = GALLERY_ICON_PATH;

public function getCMSFields(){
$fields = parent::getCMSFields();
$gridFieldConfig = GridFieldConfig_RecordEditor::create();

$gridfield = new GridField("GalleryImages", "Gallery Images", $this->GalleryImages()->filter(array(
'Title' => 'Sam'
))->sort("SortOrder"), $gridFieldConfig);
$fields->addFieldToTab('Root.GalleryImages', $gridfield);

return $fields;


you can filter record as below, for demo purpose , i used $this->GalleryImages()->filter(array( 'Title' => 'Sam'))->sort("SortOrder")

$gridfield = new GridField("GalleryImages", "Gallery Images", $this->GalleryImages()->filter(array(
'Title' => 'Sam'
))->sort("SortOrder"), $gridFieldConfig);


16 July 2014 at 12:34am Community Member, 52 Posts

Hi Thomas

Thanks for the prompt reply, This worked a treat it does exactly what i was trying to achieve.

It was the


bit that i was missing.