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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Customising the CMS /

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

[Solved] display set of results in gridfield


Go to End


5 Posts   1158 Views

Avatar
voodoochile

Community Member, 52 Posts

14 July 2014 at 10:44pm

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?

Avatar
thomas.paulson

Community Member, 107 Posts

15 July 2014 at 4:31am

Would you mind sharing more details, code?

Avatar
voodoochile

Community Member, 52 Posts

15 July 2014 at 9:05pm

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

Avatar
thomas.paulson

Community Member, 107 Posts

15 July 2014 at 10:46pm

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;
}
//*/

}

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

Avatar
voodoochile

Community Member, 52 Posts

16 July 2014 at 12:34am

Hi Thomas

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

It was the

 ->filter(array('Title'=>'sam')) 
bit that i was missing.