Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

grid field 

slindqvist edited this page · 2 revisions
Clone this wiki locally

This is how datagrid could be used in the admin interface.

Add these in the mysite/_config.php

Object::add_extension('Page', 'PageDataExtension');

And this is a demo controller:

<?php
/**
 * GridField Demo controller
 * 
 * access by going to /GridFieldDemo/
 *
 */
class GridFieldDemo extends Page_Controller {

    public static $url_rule = '/$Action/$ID/$OtherID';

    public static $allowed_actions = array(
        'GridForm',
        'index',
        'reload'
    );

    public function Title() {return 'Demo Controller';}

    public function GridForm() {
        GridFieldPresenter::add_extension('GridFieldPaginator_Extension');
        $presenter = new GridFieldPresenter();
        $presenter->paginationLimit(3);
        $presenter->sort('Title', 'desc');
        $grid = new GridField('TestGrid', 'TestGrid', new DataList('Page'), null, $presenter);
        return new Form($this, 'GridForm', new FieldList($grid), new FieldList(new FormAction('reload', 'Reload')));
    }

    public function reload($data, $form) {
        if($this->isAjax()){
            return $form->forTemplate();
        }
        return $this->render(array('GridForm'=>$form));
    }
}

class PageDataExtension extends DataExtension {

    public function extraStatics() {
        return array(
            'has_one' => array('Author'=>'Member'),
            'summary_fields' => array('Author.Name'=>'Author')
        );
    }

    public function updateCMSFields(FieldList $fields) {
        $fields->insertAfter(new DropdownField('AuthorID', 'Member', DataObject::get('Member')->map('ID','FirstName'), $this->getOwner()->AuthorID), 'Title');

        GridFieldPresenter::add_extension('GridFieldPaginator_Extension');
        $presenter = new GridFieldPresenter();
        $presenter->paginationLimit(3);
        $presenter->sort('Title', 'desc');
        $gridField = new GridField('SiteTreeList', 'SiteTreeList', new DataList('Page'), null, $presenter );
        $fields->insertAfter($gridField, 'MenuTitle');
    }
}
Something went wrong with that request. Please try again.