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.

Form Questions /

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

GridField problem with custom data.

Go to End



Community Member, 16 Posts

8 June 2013 at 8:38am

Edited: 08/06/2013 8:40am

Hi! i'm need to show custom data in a GridField, to achieve that this is the part of my code

class Player extends DataObject {
	static $has_many = array(
		'Scores' => 'Score',
	public function getCMSFields() {
		$fields = parent::getCMSFields();

		$config = GridFieldConfig_RecordEditor::create();
					'Points' => 'Points'

		$scores= new GridField(
				'Scores', // Field name
				'Score', // Field title
				$this->myScores(), // List of all related Scores

		$fields->addFieldToTab('Root.Main', $scores);
		return $fields;
	public function myScores(){
		$controller = Controller::curr();
		$bread = $controller->breadcrumbs();
		$match= $bread->last();
		$matcid= end(explode("/",$partido->Link));// the id of the match that this player belongs
		return Score::get("Score", "MatchID = $matcid AND PlayerID = $this->ID");

I'm passing $this->myScores() to the gridfield and works fine, shows me the list of Scores with the filter applied in the function "myScores", I pass this function because a "Score" have a relation with another class ("Match") too, and if I pass to the gridfield $this->Scores, shows me scores that dont have to show.

well this part is working. the problem is when I want to add a new score, when I click in the green "add Score" button, takes me to the new score screen, and when i save it, the record is saved but PlayerID is set to null in the database.

if I change $this->myScore() for $this->Scores() in the gridfield, when I save a new Score the PlayerID is saved ok.

Im very new in silverstripe, and any help will be apreciatted

my version of ss is 3.0.5.

PD: sorry for my bad english.