5102 Posts in 1520 Topics by 1116 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 465 Views |
-
SS3 the method 'setdisplayfields' does not exist on 'GridField'

17 July 2012 at 9:56pm Last edited: 17 July 2012 9:57pm
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();
}
} -
Re: SS3 the method 'setdisplayfields' does not exist on 'GridField'

17 July 2012 at 10:32pm
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
-
Re: SS3 the method 'setdisplayfields' does not exist on 'GridField'

18 July 2012 at 9:07pm
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
);
| 465 Views | ||
|
Page:
1
|
Go to Top |


