/**
  * Simple bootstrap table
  *
  * @return \ZfcDatagrid\Controller\ViewModel
  */
 public function bootstrapAction()
 {
     /* @var $grid \ZfcDatagrid\Datagrid */
     $grid = $this->getServiceLocator()->get('zf2datatablegrid');
     $grid->setTitle('Persons');
     $grid->setDefaultItemsPerPage(5);
     // die('fine');
     $grid->setDataSource($this->getServiceLocator()->get('zf2datatable.examples.data.doctrine2')->getPersons());
     $grid->getDataSource()->setEntity('\\Zf2datatable\\Examples\\Entity\\Person');
     $identity = $grid->getIdentyColumns();
     $col = new Column\Select('id', 'p');
     $col->setIdentity();
     $grid->addColumn($col);
     /**
      * Gravatar example
      * - take the email from the datasource
      * - object makes the rest :-)
      *
      * @note Could be whatever you want -> Grab data from everywhere you want with dynamic parameters :-)
      */
     $colEmail = new Column\Select('email', 'p');
     $colEmail->setLabel('E-Mail');
     $colEmail->setHidden();
     $dataPopulation = new Column\DataPopulation\Object();
     $dataPopulation->setObject(new Column\DataPopulation\Object\Gravatar());
     $dataPopulation->addObjectParameterColumn('email', $colEmail);
     $col = new Column\ExternalData('avatar');
     $col->setLabel('Avatar');
     $col->setType(new Type\Image());
     $col->setDataPopulation($dataPopulation);
     $grid->addColumn($col);
     $col = new Column\Select('displayName', 'p');
     $col->setLabel('Displayname');
     $col->setWidth(25);
     $col->setSortDefault(1, 'ASC');
     $col->addStyle(new Style\Bold());
     $grid->addColumn($col);
     $col = new Column\Select('familyName', 'p');
     $col->setLabel('Familyname');
     $col->setWidth(15);
     $grid->addColumn($col);
     $col = new Column\Select('givenName', 'p');
     $col->setLabel('Givenname');
     $col->setWidth(15);
     $col->setSortDefault(2, 'DESC');
     $grid->addColumn($col);
     $grid->addColumn($colEmail);
     $col = new Column\Select('gender', 'p');
     $col->setLabel('Gender');
     $col->setWidth(10);
     $col->setReplaceValues(array('m' => 'male', 'f' => 'female'));
     $col->setTranslationEnabled(true);
     $grid->addColumn($col);
     $col = new Column\Select('age', 'p');
     $col->setLabel('Age');
     $col->setWidth(5);
     $col->setType(new Type\Number());
     $col->setFilterDefaultValue('>=20');
     $style = new Style\Color(Style\Color::$RED);
     $style->addByValue($col, 20);
     $col->addStyle($style);
     $grid->addColumn($col);
     $colType = new Type\Number();
     $colType->addAttribute(\NumberFormatter::FRACTION_DIGITS, 2);
     $colType->setSuffix(' kg');
     $col = new Column\Select('weight', 'p');
     $col->setLabel('Weight');
     $col->setWidth(10);
     $col->setType($colType);
     $grid->addColumn($col);
     $col = new Column\Select('birthday', 'p');
     $col->setLabel('Birthday');
     $col->setWidth(10);
     $col->setType(new Type\DateTime());
     $col->setUserSortDisabled(true);
     $grid->addColumn($col);
     $colType = new Type\DateTime('Y-m-d H:i:s', \IntlDateFormatter::MEDIUM, \IntlDateFormatter::MEDIUM);
     $colType->setSourceTimezone('Europe/Vienna');
     $colType->setOutputTimezone('UTC');
     $col = new Column\Select('changeDate', 'p');
     $col->setLabel('Last change');
     $col->setWidth(15);
     $col->setType($colType);
     $grid->addColumn($col);
     $grid->setIsCrud(true);
     $grid->setFrmMainCrud('frmperson');
     $grid->render();
     return $grid->getResponse();
 }
 /**
  * Simple bootstrap table
  *
  * @return \ZfcDatagrid\Controller\ViewModel
  */
 public function bootstrapAction()
 {
     $sm = $this->getServiceLocator();
     $translator = $sm->get('translator');
     /* @var $dbAdapter \Zend\Db\Adapter\Adapter */
     $dbAdapter = $this->getServiceLocator()->get('zf2datatable_adapter');
     /* @var $grid \ZfcDatagrid\Datagrid */
     $sqlSource = $this->getServiceLocator()->get('Zf2datatable.examples.data.zendSelect')->getPersons();
     //$tableGataway = new \Zf2datatable\Examples\Tablegateway\PersonTableGateway($this->getServiceLocator ()->get('zf2datatable_adapter'));
     //$sqlSource=   (new \Zf2datatable\DataSource\ZendTableGateway($tableGataway))->query('person');
     //$sqlSource=   $tableGataway;
     $grid = $this->getServiceLocator()->get('zf2datatablegrid');
     $grid->setTitle('Persons');
     $grid->setIsCrud(true);
     $grid->setDefaultItemsPerPage(5);
     $grid->setDataSource($sqlSource, $dbAdapter);
     //$grid->getDataSource()->setSelectDetail($sqlSource);
     $grid->getDataSource()->setTable('person', 'p');
     //$grid->setFrmMainCrud ( $this->formConfig );
     // form to edit/insert
     //$grid->setFrmMainCrud(new \Zf2datatable\Examples\Form\Person());
     //$grid->setFrmMainCrud(new \Zf2datatable\Examples\Entity\Person());
     //$grid->setFrmMainCrud ( $this->formConfig );
     $identity = $grid->getIdentyColumns();
     $col = new Column\Select('id', 'p');
     $col->setIdentity();
     $grid->addColumn($col);
     /**
      * Gravatar example
      * - take the email from the datasource
      * - object makes the rest :-)
      *
      * @note Could be whatever you want -> Grab data from everywhere you want with dynamic parameters :-)
      */
     $colEmail = new Column\Select('email', 'p');
     $colEmail->setLabel('E-Mail');
     $colEmail->setHidden();
     $dataPopulation = new Column\DataPopulation\Object();
     $dataPopulation->setObject(new Column\DataPopulation\Object\Gravatar());
     $dataPopulation->addObjectParameterColumn('email', $colEmail);
     $col = new Column\ExternalData('avatar');
     $col->setLabel('Avatar');
     $col->setDataPopulation($dataPopulation);
     $col->setType(new Type\Image());
     $grid->addColumn($col);
     $col = new Column\Select('displayName', 'p');
     $col->setLabel('Displayname');
     $col->setWidth(15);
     $col->setSortDefault(1, 'ASC');
     $col->addStyle(new Style\Bold());
     $grid->addColumn($col);
     $col = new Column\Select('familyName', 'p');
     $col->setLabel('Familyname');
     $col->setWidth(15);
     $grid->addColumn($col);
     $col = new Column\Select('givenName', 'p');
     $col->setLabel('Givenname');
     $col->setWidth(15);
     $col->setSortDefault(2, 'DESC');
     $grid->addColumn($col);
     $grid->addColumn($colEmail);
     $colgender = new Column\Select('gender', 'p');
     $colgender->setLabel('Gender');
     $colgender->setWidth(10);
     $colgender->setReplaceValues(array('m' => 'male', 'f' => 'female'));
     $colgender->setTranslationEnabled(true);
     $grid->addColumn($colgender);
     $col = new Column\Select('age', 'p');
     $col->setLabel('Age');
     $col->setWidth(5);
     $col->setType(new Type\Number());
     $style = new Style\Color(Style\Color::$RED);
     $style->addByValue($col, 20);
     $col->addStyle($style);
     $grid->addColumn($col);
     $colType = new Type\Number();
     $colType->addAttribute(\NumberFormatter::FRACTION_DIGITS, 2);
     $colType->setSuffix(' kg');
     $col = new Column\Select('weight', 'p');
     $col->setLabel('Weight');
     $col->setWidth(10);
     $col->setType($colType);
     $grid->addColumn($col);
     $colType = new Type\DateTime('Y-m-d H:i:s', \IntlDateFormatter::MEDIUM, \IntlDateFormatter::MEDIUM);
     $colType->setSourceTimezone('Europe/Vienna');
     $colType->setOutputTimezone('UTC');
     $colType->setLocale('it_IT');
     $colType->setDaterangePickerEnabled(true);
     $col = new Column\Select('birthday', 'p');
     $col->setLabel('Birthday');
     $col->setWidth(25);
     $col->setType($colType);
     //$col->setType ( new Type\DateTime ('Y-m-d H:i:s') );
     //$col->setUserSortDisabled ( true );
     $grid->addColumn($col);
     $col = new Column\Select('changeDate', 'p');
     $col->setLabel('Last change');
     $col->setWidth(30);
     $col->setType($colType);
     $grid->addColumn($col);
     $col = new Column\Select('name', 'g');
     $col->setLabel('Group');
     $col->setWidth(10);
     /*$col->setReplaceValues ( array (
     		    '1' => 'guest',
     		    '2' => 'member',
     		    '3' => 'admin',
     		    '4' => 'superdamin'
     		) );*/
     $grid->addColumn($col);
     /*$actionview = new Column\Action\Button ();
     		$actionview->setLabel ( 'View Record' );
     		$actionview->setAttribute ( 'href', "?operation=v&{$identity[0]}=" . $actionview->getRowIdPlaceholder () );
     		$grid->setRowClickAction ( $actionview );*/
     // gestisco gli overrite
     $grid->setFrmElementSource(array('primaryGroupId' => array('source' => 'db', 'table' => 'group', 'id' => 'id', 'value' => 'name', 'type' => 'SELECT'), 'gender' => array('source' => 'array', 'array_value' => array('m' => 'Male', 'f' => 'Female'), 'type' => 'SELECT')));
     //$grid->setFrmMainCrud(new \Zf2datatable\Examples\Form\Person());
     //$grid->setFrmMainCrud(new \Zf2datatable\Examples\Entity\Person());
     $grid->setFrmMainCrud('frmperson');
     $grid->setConditionCrudColumn(array('editCrud' => array('field' => $colgender, 'filter' => 'male', 'filter_crud' => 'm', 'filter_perator' => \Zf2datatable\Filter::EQUAL), 'deleteCrud' => array('field' => $colgender, 'filter' => 'male', 'filter_crud' => 'm', 'filter_perator' => \Zf2datatable\Filter::EQUAL)));
     $grid->render();
     return $grid->getResponse();
 }
 private function getGrid()
 {
     die('xxx');
     /* @var $grid \ZfcDatagrid\Datagrid */
     $grid = $this->getServiceLocator()->get('ZfcDatagrid\\Datagrid');
     $grid->setTitle('Persons');
     $grid->setDefaultItemsPerPage(5);
     $grid->setDataSource($this->getServiceLocator()->get('zfcDatagrid.examples.data.phpArray')->getPersons());
     $col = new Column\Select('id');
     $col->setIdentity();
     $grid->addColumn($col);
     $action = new Action\Mass();
     $action->setTitle('test');
     $action->setLink('/test');
     $grid->addMassAction($action);
     /**
      * Gravatar example
      * - take the email from the datasource
      * - object makes the rest :-)
      *
      * @note Could be whatever you want -> Grab data from everywhere you want with dynamic parameters :-)
      */
     $colEmail = new Column\Select('email');
     $colEmail->setLabel('E-Mail');
     $colEmail->setHidden(true);
     $grid->addColumn($colEmail);
     $dataPopulation = new Column\DataPopulation\Object();
     $dataPopulation->setObject(new Column\DataPopulation\Object\Gravatar());
     $dataPopulation->addObjectParameterColumn('email', $colEmail);
     $col = new Column\ExternalData('avatar');
     $col->setLabel('Avatar');
     $col->setDataPopulation($dataPopulation);
     $col->setType(new Type\Image());
     $grid->addColumn($col);
     $col = new Column\Select('displayName');
     $col->setLabel('Displayname');
     $col->setWidth(25);
     $col->setSortDefault(1, 'ASC');
     $col->setFormatter(new Email());
     $col->addStyle(new Style\Bold());
     $grid->addColumn($col);
     $col = new Column\Select('familyName');
     $col->setLabel('Familyname');
     $col->setWidth(15);
     $grid->addColumn($col);
     $col = new Column\Select('givenName');
     $col->setLabel('Givenname');
     $col->setWidth(15);
     $col->setSortDefault(2, 'DESC');
     $grid->addColumn($col);
     $style = new Style\BackgroundColor(array(200, 200, 200));
     $style->addByValue($col, 'Martin');
     $grid->addRowStyle($style);
     $col = new Column\Select('gender');
     $col->setLabel('Gender');
     $col->setWidth(10);
     $col->setReplaceValues(array('m' => 'male', 'f' => 'female'));
     $style = new Style\BackgroundColor(array(200, 100, 100));
     $style->addByValue($col, 'male');
     $col->addStyle($style);
     $col->setTranslationEnabled(true);
     $grid->addColumn($col);
     $col = new Column\Select('age');
     $col->setLabel('Age');
     $col->setWidth(5);
     $col->setType(new Type\Number());
     $col->setFilterDefaultValue('>=20');
     $style = new Style\Color(Style\Color::$RED);
     $style->addByValue($col, 20);
     $col->addStyle($style);
     $grid->addColumn($col);
     $colType = new Type\Number();
     $colType->addAttribute(\NumberFormatter::FRACTION_DIGITS, 2);
     $colType->setSuffix(' kg');
     $col = new Column\Select('weight');
     $col->setLabel('Weight');
     $col->setWidth(10);
     $col->setType($colType);
     $col->setFilterDefaultOperation(\ZfcDatagrid\Filter::GREATER_EQUAL);
     $grid->addColumn($col);
     $col = new Column\Select('birthday');
     $col->setLabel('Birthday');
     $col->setWidth(10);
     $col->setType(new Type\DateTime());
     $col->setUserSortDisabled(true);
     $grid->addColumn($col);
     $colType = new Type\DateTime('Y-m-d H:i:s', \IntlDateFormatter::MEDIUM, \IntlDateFormatter::MEDIUM);
     $colType->setSourceTimezone('Europe/Vienna');
     $colType->setOutputTimezone('UTC');
     $col = new Column\Select('changeDate');
     $col->setLabel('Last change');
     $col->setWidth(15);
     $col->setType($colType);
     $grid->addColumn($col);
     $action = new Column\Action\Button();
     $action->setLabel('test');
     $action->setAttribute('href', '/someAction/id/' . $action->getRowIdPlaceholder());
     $col = new Column\Action();
     $col->setLabel('Actions');
     $col->setWidth(10);
     $col->addAction($action);
     $grid->addColumn($col);
     $grid->setRowClickAction($action);
     return $grid;
 }