Jump to:

7935 Posts in 1536 Topics by 943 members

DataObjectManager Module

SilverStripe Forums » DataObjectManager Module » Readonly GridField Column

Discuss the DataObjectManager module, and the related ImageGallery module.

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

Page: 1
Go to End
Author Topic: 504 Views
  • keyvan
    Avatar
    Community Member
    1 Post

    Readonly GridField Column Link to this post

    I like to make a Column in a GridFiled readonly also in the following edit-form has same filed as readonly.
    The idea is to show a list of cameras but name of camera and last frame were readonly.

    Here is my code:

    class CameraObject extends DataObject
    {
       public static $db = array(
          'Publish' => "Enum('No, Yes', 'No')",
          'Name'=>'Varchar(200)',
          'Alias'=>'Varchar(200)',
       );

       public static $has_one = array(
          'LastFrame'=>'Image',
       );   
    }

    class CameraPage_Controller extends Page_Controller
    {

    static $allowed_actions = array('index', 'AllCameras');

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

    public function index(SS_HTTPRequest $request)
    {
    $this->Content = $this->AllCameras();
    return $this->render();
    }

    public function AllCameras()
    {
    $records = CameraObject::get();   
       
    $config = GridFieldConfig::create()->addComponents(
           new GridFieldSortableHeader(),
           new GridFieldDataColumns(),
           new GridFieldPaginator(10),
           new GridFieldEditButton(),
           new GridFieldDetailForm()
          );

    $gridField = new GridField('cameras', 'Cameras', $records, $config);
          
    $dataColumns = $config->getComponentByType('GridFieldDataColumns');
    $dataColumns->setDisplayFields(array(   
    'Publish' => 'Publish',
    'Name' => 'Name',
    'Alias' => 'Alias',    
    'LastFrame' => 'LastFrame',   
    ));
                
    $form = new Form($this, "AllCameras", new FieldList($gridField), new FieldList());      

    return $form;
    }
    }

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