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.

We're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

DatePicker in GridField SS 3

Go to End

10 Posts   3335 Views


Community Member, 91 Posts

6 September 2012 at 10:39pm

Edited: 07/09/2012 1:41am

Hi All,

I'm trying to get a DatePicker in my GridField. The Datefield DataObject is of the type Date. It seams also to be that getCMSFields_forPopup doesn't work at all?


class Agenda extends Page {
  public static $has_many = array(
    'Optredens' => 'Optreden'
  public function getCMSFields(){
    $fields = parent::getCMSFields();
    $gridFieldConfig = GridFieldConfig::create()->addcomponents(
      new GridFieldToolbarHeader(),
      new GridFieldAddNewButton('toolbar-header-right'),
      new GridFieldSortableHeader(),
      new GridFieldDataColumns(),
      new GridFieldPaginator(10),
      new GridFieldEditButton(),
      new GridFieldDeleteAction(),
      new GridFieldDetailForm()
    $gridField = new GridField("Optredens", "Optredens:", $this->Optredens(), $gridFieldConfig);
        'Datum' => 'Date'
    $fields->addFieldToTab("Root.Optredens", $gridField);
        return $fields;


  class Optreden extends DataObject{
    static $db = array(
      'Locatie' => 'Varchar(100)',
      'Plaats' => 'Varchar(100)',
      'Datum' => 'Date',
      'Tijd' => 'Varchar(15)',
      'Omschrijving' => 'HTMLText'
    static $has_one = array(
    public static $summary_fields = array(
    function getCMSFields_forPopup() {
      $fields = new FieldList();
      $fields->push(TextField('Locatie','Locatie (feest naam)'));
      $fields->push(TextField('Plaats','Plaats (dorp / stad)'));
      $fields->push(DateField('Datum', 'Datum'));
      $fields->push(TextField('Tijd', 'Tijd'));
      $fields->push(TextareaField('Omschrijving', 'Omschrijving'));
      return $fields;

Optic Blaze

Community Member, 190 Posts

11 September 2012 at 11:22am

I had a similar problem that i managed to fix.

I however did not use the 'function getCMSFields_forPopup()' syntax but used the following:

function getCMSFields() {
// Date field is created that displays calendar
$dateField = new DateField('Datum');
$dateField->setConfig('showcalendar', true);

$fields = new FieldSet(
return $fields;

When i used the above code in my app the grid field worked very well.

You can also set the default fields that show up in the grid field with the following code.
If we wanted to show 'Locatie','Datum' and 'Plaats' as default fields in grid field we do the following in the
Optreden.php file

// Sets the sumary fields that will be displayed in teh grid field
static $summary_fields = array(

Hope it helps


Community Member, 91 Posts

12 September 2012 at 12:33am

Edited: 12/09/2012 12:34am

Hi Optic Blaze,

Thanks for your answer. I think your solution works well for v2.4.x, but not for SS 3.x (FieldSet is deprecated).

In 3.x DateField wil be called automatically when your dbfield is set Date (or DateTime).

The error was in /framwork/javascript/DateField.js, line 12:

if(!config.showcalendar) return;

I commented that line out and the DatePicker works fine by now :)


Forum Moderator, 1391 Posts

18 September 2012 at 4:33am

Edited: 18/09/2012 4:35am

Hi quanto,

Although your solution works for you, it shouldn't be necessary. Afaik the DatePicker doesn't necessarily show in the DateField by default in 3.0 - you should still explicitly set it, just like in Optic Blazes' example, the same way you set min/max values and determine the dateformat:

function getCMSFields() {
	$fields = new FieldList(
		$dateField = new DateField('Datum', 'Datum'),
	$dateField->setConfig('showcalendar', true);

	// optional:

	return $fields;

If you don't it's still a datefield, with validation, but without the datepicker :-)

Cheers, Martine


Community Member, 3 Posts

12 October 2012 at 1:23am

Edited: 12/10/2012 1:24am


I had the same problem in my current installation 3.0.2.
With the code you supplied I am now able to enter a date with the date picker :)

Unfortunally if I have entered a dataset I could not see my cms page again, cause of an error?!

Is ist possible that the grid has a problem with displaying date values in the table ?

Where could I find informations about the error - log ?



Optic Blaze

Community Member, 190 Posts

12 October 2012 at 1:38am

Hi there.

To check for errors you need to do the following:

1) Make sure that you are in dev mode. In your _config file make sure you have the following line:

//Set development mode //

2) I assume you are using wamp or mamp.
a) click on the wamp icon in your system tray
b) click on php and then php settings
c) select 'display errors'

This should then show us where the problem is. It could just be a formatting error


Community Member, 3 Posts

12 October 2012 at 4:30am

Edited: 12/10/2012 4:40am

Hi Optic Blaze,

now I see a popup with the following message:

Error at line 661 of D:\programme\xampp\htdocs\SilverStripe\framework\core\Object.php

Looking at the Object.php -->
throw new Exception("Object->__call(): the method '$method' does not exist on '$this->class'", 2175);

snip ..




with my Termin defined as

class Termin extends DataObject {
    static $db = array(
        'FirstDate' => 'Date',        
        'DateRange' => 'Varchar',
        'Description' => 'HTMLVarchar'
    static $has_one = array(
        'JahrsTermine' => 'JahrsTerminePage'
 public function getCMSFields() {
        $fields = parent::getCMSFields();
        $dateField = new DateField('FirstDate');
        $dateField->setConfig('showcalendar', true);
        $fields->push( $dateField);
        $fields->push( new TextField('DateRange','Termin(e)'));
       $fields->push( new HTMLEditorField('Description','Beschreibung'));
        return $fields;

Regards Andy

Optic Blaze

Community Member, 190 Posts

12 October 2012 at 4:36am

You need to post your code that you used the datepicker . It sounds like you referenced something that does not exist in the code.

Go to Top