Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

DataObjectManager Module /

Discuss the DataObjectManager module, and the related ImageGallery module.

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

Readonly GridField Column


Go to End
Reply


835 Views

Avatar
keyvan

Community Member, 1 Post

5 September 2013 at 6:26pm

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;
}
}