Jump to:

5453 Posts in 1674 Topics by 1198 members

Customising the CMS

SilverStripe Forums » Customising the CMS » SS3 the method 'setdisplayfields' does not exist on 'GridField'

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

Page: 1
Go to End
Author Topic: 862 Views
  • Thomashv
    Avatar
    Community Member
    32 Posts

    SS3 the method 'setdisplayfields' does not exist on 'GridField' Link to this post

    Hi,

    I have problems with the setdisplayfields method in SilverStripe 3.0.0. It says that the method 'setdisplayfields' does not exist on 'GridField'. Is there anybody else that has experiend similar problems? I post my code here and hope some of you have an idea of what I'm doing wrong here...

    class HomePage extends Page {
       public static $db = array(
       
       );
       
       public static $has_many = array(
          'HomePageSlides' => 'HomePageSlide' // link the slide items
       );
          
       function getCMSFields() {
          $fields = parent::getCMSFields();
          
          $gridfieldConfig = GridFieldConfig::create()->addComponents(
             new GridFieldToolbarHeader(),
    new GridFieldAddNewButton('toolbar-header-right'),
             new GridFieldSortableHeader(),
             new GridFieldDataColumns(),
             new GridFieldPaginator(15),
             new GridFieldEditButton(),
             new GridFieldDeleteAction(),
             new GridFieldDetailForm()
          );
          
          

          $gridfield = new GridField("HomePageSlides", "Slides", $this->HomePageSlides(), $gridfieldConfig);
          
           $gridfield->setDisplayFields(array(
              'ID' => 'ID'
              ));
          
          $fields->addFieldToTab('Root.Slides', $gridfield);
          
          return $fields;
       }
    }

    class HomePage_Controller extends Page_Controller {

       public static $allowed_actions = array (
       );

       public function init() {
          parent::init();
       }
    }

  • James Bolitho
    Avatar
    Community Member
    33 Posts

    Re: SS3 the method 'setdisplayfields' does not exist on 'GridField' Link to this post

    Hi Thomashv,

    I was having the same issue with 'setFieldCasting'. It looks like the documentation on this needs to be updated because it seems that this has to be implemented differently now. I looked at the AssetAdmin.php in the cms/code/controllers/ folder for inspiration.

    I would try this and see if it works:

    $gridfield = new GridField("HomePageSlides", "Slides", $this->HomePageSlides(), $gridfieldConfig);

    $columns = $gridField->getConfig()->getComponentByType('GridFieldDataColumns'); //new line that needs to be added to your code

    $columns->setDisplayFields(array( //change $gridfield in your code to $columns
    'ID' => 'ID'
    ));

    Hope that helps.

    Cheers,

    Jim

  • dpde
    Avatar
    Community Member
    14 Posts

    Re: SS3 the method 'setdisplayfields' does not exist on 'GridField' Link to this post

    You can use the variable $summary_fields in your DataObject or something like this:

    $gridColumns = new GridFieldDataColumns();
    $gridColumns->setDisplayFields(array(
    'ID' => 'ID',
    'Title' => 'Titel'
    ));

    $gridFieldConfig = GridFieldConfig::create()->addComponents(
    new GridFieldToolbarHeader(),
    new GridFieldAddNewButton('toolbar-header-right'),
    new GridFieldSortableHeader(),
    //new GridFieldDataColumns(),
    new GridFieldPaginator(10),
    new GridFieldEditButton(),
    new GridFieldDeleteAction(),
    new GridFieldDetailForm()
    $gridColumns
    );

  • Martin D.
    Avatar
    Community Member
    20 Posts

    Re: SS3 the method 'setdisplayfields' does not exist on 'GridField' Link to this post

    $summary_fields doesn't seems to be working but Jim's solution does.

    $columns = $listField->getConfig()->getComponentByType('GridFieldDataColumns');
    $columns->setDisplayFields(array(
    'Name' => 'Name',
    'Prices' => 'Prices'
    ));

    'setDisplayFields' is a method of GridFieldDataColumns, not the GridField itself.

    862 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.