Merge pull request #104 from robert-h-curry/7010-gridfield-set-display-fields

ENHANCEMENT: Part of fix to #7010. Change to some gridfield calls to set...
This commit is contained in:
Sean Harvey 2012-04-18 19:31:27 -07:00
commit 68a5686cfe
3 changed files with 15 additions and 11 deletions

View File

@ -139,14 +139,15 @@ JS
new GridFieldDetailForm() new GridFieldDetailForm()
); );
$gridField = new GridField('File','Files', $this->getList(), $gridFieldConfig); $gridField = new GridField('File','Files', $this->getList(), $gridFieldConfig);
$gridField->setDisplayFields(array( $columns = $gridField->getConfig()->getComponentByType('GridFieldDataColumns');
$columns->setDisplayFields(array(
'StripThumbnail' => '', 'StripThumbnail' => '',
// 'Parent.FileName' => 'Folder', // 'Parent.FileName' => 'Folder',
'Title' => _t('File.Name'), 'Title' => _t('File.Name'),
'Created' => _t('AssetAdmin.CREATED', 'Date'), 'Created' => _t('AssetAdmin.CREATED', 'Date'),
'Size' => _t('AssetAdmin.SIZE', 'Size'), 'Size' => _t('AssetAdmin.SIZE', 'Size'),
)); ));
$gridField->setFieldCasting(array( $columns->setFieldCasting(array(
'Created' => 'Date->Nice' 'Created' => 'Date->Nice'
)); ));
$gridField->setAttribute( $gridField->setAttribute(

View File

@ -676,7 +676,8 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
new GridFieldPaginator(15) new GridFieldPaginator(15)
); );
$gridField = new GridField('Page','Pages', $list, $gridFieldConfig); $gridField = new GridField('Page','Pages', $list, $gridFieldConfig);
$columns = $gridField->getConfig()->getComponentByType('GridFieldDataColumns');
// Don't allow navigating into children nodes on filtered lists // Don't allow navigating into children nodes on filtered lists
if($params){ if($params){
$gridField->setDisplayFields(array( $gridField->setDisplayFields(array(
@ -685,7 +686,7 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
'LastEdited' => _t('SiteTree.LASTUPDATED', 'Last Updated'), 'LastEdited' => _t('SiteTree.LASTUPDATED', 'Last Updated'),
)); ));
}else{ }else{
$gridField->setDisplayFields(array( $columns->setDisplayFields(array(
'listChildrenLink' => "", 'listChildrenLink' => "",
'getTreeTitle' => _t('SiteTree.PAGETITLE', 'Page Title'), 'getTreeTitle' => _t('SiteTree.PAGETITLE', 'Page Title'),
'Created' => _t('SiteTree.CREATED', 'Date Created'), 'Created' => _t('SiteTree.CREATED', 'Date Created'),
@ -693,13 +694,13 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
)); ));
} }
$gridField->setFieldCasting(array( $columns->setFieldCasting(array(
'Created' => 'Date->Ago', 'Created' => 'Date->Ago',
'LastEdited' => 'Date->Ago', 'LastEdited' => 'Date->Ago',
)); ));
$controller = $this; $controller = $this;
$gridField->setFieldFormatting(array( $columns->setFieldFormatting(array(
'listChildrenLink' => function(&$item) use($controller) { 'listChildrenLink' => function(&$item) use($controller) {
$num = $item->numChildren(); $num = $item->numChildren();
if($num) { if($num) {

View File

@ -162,6 +162,7 @@ class ReportAdmin extends LeftAndMain implements PermissionProvider {
new GridFieldExportButton() new GridFieldExportButton()
); );
$gridField = new GridField('Report',$report->title(), $report->sourceRecords(array(), null, null), $gridFieldConfig); $gridField = new GridField('Report',$report->title(), $report->sourceRecords(array(), null, null), $gridFieldConfig);
$columns = $gridField->getConfig()->getComponentByType('GridFieldDataColumns');
$displayFields = array(); $displayFields = array();
$fieldCasting = array(); $fieldCasting = array();
$fieldFormatting = array(); $fieldFormatting = array();
@ -181,9 +182,9 @@ class ReportAdmin extends LeftAndMain implements PermissionProvider {
$displayFields[$source] = isset($info['title']) ? $info['title'] : $source; $displayFields[$source] = isset($info['title']) ? $info['title'] : $source;
} }
$gridField->setDisplayFields($displayFields); $columns->setDisplayFields($displayFields);
$gridField->setFieldCasting($fieldCasting); $columns->setFieldCasting($fieldCasting);
$gridField->setFieldFormatting($fieldFormatting); $columns->setFieldFormatting($fieldFormatting);
$fields->push($gridField); $fields->push($gridField);
} else { } else {
@ -195,10 +196,11 @@ class ReportAdmin extends LeftAndMain implements PermissionProvider {
new GridFieldFooter() new GridFieldFooter()
); );
$gridField = new GridField('Reports','Reports', $this->Reports(), $gridFieldConfig); $gridField = new GridField('Reports','Reports', $this->Reports(), $gridFieldConfig);
$gridField->setDisplayFields(array( $columns = $gridField->getConfig()->getComponentByType('GridFieldDataColumns');
$columns->setDisplayFields(array(
'title' => 'Title', 'title' => 'Title',
)); ));
$gridField->setFieldFormatting(array( $columns->setFieldFormatting(array(
'title' => '<a href=\"$Link\" class=\"cms-panel-link\">$value</a>' 'title' => '<a href=\"$Link\" class=\"cms-panel-link\">$value</a>'
)); ));
$gridField->addExtraClass('all-reports-gridfield'); $gridField->addExtraClass('all-reports-gridfield');