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.

General Questions

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

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

Set title of dataobject in gridfield header


Reply

2 Posts   275 Views

Avatar
Bereusei

11 September 2013 at 8:32pm Community Member, 94 Posts

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

12 September 2013 at 12:21am Community Member, 94 Posts

Found the solution:

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

so simple...