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.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

Set title of dataobject in gridfield header


Go to End


2 Posts   989 Views

Avatar
Bereusei

Community Member, 96 Posts

11 September 2013 at 8:32pm

Hey guys,

I have a little problem. I have a DataObject "Job" with a "title" and a gridfield.
What I wanna do is, to set the title of the DataObject in the header of the gridfield (in the backend), so that the title is shown up in die printview if I click the printbutton.

class Job extends DataObject{

static $db = array( 'Title' => 'Varchar(255)' );
static $has_many = array(
			'JobWorktimes' => 'JobWorktime'
);

public function getCMSFields() {
        	$fields = parent::getCMSFields();
                /* Worktimes */
        	$config = GridFieldConfig_RelationEditor::create();
        	$config->addComponent(new GridFieldPrintButton());
        	
        	$WorkField = new GridField(
            	'JobWorktimes',
            	'JobWorktime', 
            	$this->JobWorktimes(), 
            	$config
        	);
        	
        	$fields->addFieldToTab('Root.Main', $WorkField);
        	 
        	return $fields;
      }
}

Now the gridfield title is named normally "Worktime", but I wanna to set the title of the dataobject.

I´ve tried something like this:

$config->addComponent(new GridFieldToolbarHeader($this->title));

But any string I´ve set in there, doesn´t appear and it creates a "double" headerbar.
Is it possible to change the origanal name ("Worktime") in the header of the gridfield?

Avatar
Bereusei

Community Member, 96 Posts

12 September 2013 at 12:21am

Found the solution:

$WorkFieldTitle = $this->Client()->Name . ' - ' . $this->title;
        	
$WorkField = new GridField(
           'JobWorktimes',
           $WorkFieldTitle, 
           $this->JobWorktimes(), 
           $config
);

so simple...