Jump to:

23453 Posts in 18904 Topics by 2877 members

General Questions

SilverStripe Forums » General Questions » Set title of dataobject in gridfield header

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

Page: 1
Go to End
Author Topic: 253 Views
  • Bereusei
    Avatar
    Community Member
    94 Posts

    Set title of dataobject in gridfield header Link to this post

    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?

  • Bereusei
    Avatar
    Community Member
    94 Posts

    Re: Set title of dataobject in gridfield header Link to this post

    Found the solution:

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

    so simple...

    253 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.