protected function createComponentGrid($name)
 {
     $grid = new Grid($this, $name);
     $repository = $this->database->getRepository('App\\Models\\Doctrine\\Entities\\User');
     $model = new \Grido\DataSources\Doctrine($repository->createQueryBuilder('a')->addSelect('c')->innerJoin('a.country', 'c'), array('country' => 'c.title'));
     // Map country column to the title of the Country entity
     $grid->model = $model;
     $grid->addColumnText('firstname', 'Firstname')->setFilterText()->setSuggestion();
     $grid->addColumnText('surname', 'Surname')->setSortable()->setFilterText()->setSuggestion();
     $grid->addColumnText('gender', 'Gender')->setSortable()->cellPrototype->class[] = 'center';
     $grid->addColumnDate('birthday', 'Birthday', \Grido\Components\Columns\Date::FORMAT_TEXT)->setSortable()->setFilterDate()->setCondition($grid->birthdayFilterCondition);
     $grid->getColumn('birthday')->cellPrototype->class[] = 'center';
     $grid->addColumnText('country', 'Country')->setSortable()->setCustomRender(function ($item) {
         $baseUri = $this->getBaseUri();
         $img = Html::el('img')->src("{$baseUri}/img/flags/{$item->country_code}.gif");
         return "{$img} {$item->country}";
     })->setFilterText()->setSuggestion();
     $grid->addColumnText('card', 'Card')->setSortable()->setColumn('cctype')->setReplacement(array('MasterCard' => Html::el('b')->setText('MasterCard')))->cellPrototype->class[] = 'center';
     $grid->addColumnEmail('emailaddress', 'Email')->setSortable()->setFilterText();
     $grid->getColumn('emailaddress')->cellPrototype->class[] = 'center';
     $grid->addColumnText('centimeters', 'Height')->setSortable()->setFilterNumber();
     $grid->getColumn('centimeters')->cellPrototype->class[] = 'center';
     $grid->addFilterSelect('gender', 'Gender', array('' => '', 'female' => 'female', 'male' => 'male'));
     $grid->addFilterSelect('card', 'Card', array('' => '', 'MasterCard' => 'MasterCard', 'Visa' => 'Visa'))->setColumn('cctype');
     $grid->addFilterCheck('preferred', 'Only preferred girls :)')->setCondition(array(TRUE => array(array('gender', 'AND', 'centimeters'), array('= ?', '>= ?'), array('female', 170))));
     $grid->addActionHref('edit', 'Edit')->setIcon('pencil');
     $grid->addActionHref('delete', 'Delete')->setIcon('trash')->setConfirm(function ($item) {
         return "Are you sure you want to delete {$item->firstname} {$item->surname}?";
     });
     $operation = array('print' => 'Print', 'delete' => 'Delete');
     $grid->setOperation($operation, $this->handleOperations)->setConfirm('delete', 'Are you sure you want to delete %i items?');
     $grid->filterRenderType = $this->filterRenderType;
     $grid->setExport();
 }
Exemple #2
0
 protected function createComponentGrid($name)
 {
     $grid = new Grid($this, $name);
     $grid->model = $this->getData();
     $grid->filterRenderType = Filter::RENDER_OUTER;
     $grid->translator->lang = 'cs';
     $grid->defaultPerPage = 5;
     $grid->addColumnNumber('id', '#')->cellPrototype->class[] = 'center';
     $header = $grid->getColumn('id')->headerPrototype;
     $header->rowspan = "2";
     $header->style['width'] = '0.1%';
     $grid->addColumnText('firstname', 'Jméno')->setSortable()->setFilterText()->setSuggestion();
     $grid->getColumn('firstname')->headerPrototype->style['width'] = '10%';
     $grid->addColumnText('surname', 'Příjmení')->setSortable()->setFilterText()->setSuggestion();
     $grid->getColumn('surname')->headerPrototype->style['width'] = '10%';
     $grid->addColumnNumber('allowance', 'Kapesné [CZK]', 2, ',', ' ')->setSortable()->setFilterNumber();
     $grid->getColumn('allowance')->cellPrototype->class[] = 'center';
     $grid->getColumn('allowance')->headerPrototype->class[] = 'center';
     $grid->getColumn('allowance')->headerPrototype->style['width'] = '6%';
     $grid->addFilterCustom('name', new \Nette\Forms\Controls\TextArea('Jméno nebo příjmení'))->setColumn('firstname')->setColumn('surname', \Grido\Components\Filters\Condition::OPERATOR_OR)->setCondition('LIKE ?')->setFormatValue('%%value%');
     $grid->addColumnDate('last_login', 'Poslední přihlášení')->setSortable()->setDateFormat(\Grido\Components\Columns\Date::FORMAT_DATETIME)->setReplacement(array(NULL => 'Nikdy'));
     $grid->getColumn('last_login')->cellPrototype->class[] = 'center';
     $grid->getColumn('last_login')->headerPrototype->class[] = 'center';
     $grid->getColumn('last_login')->headerPrototype->style['width'] = '9%';
     $grid->addColumnBoolean('ok', 'OK')->setSortable();
     $grid->addActionHref('edit', 'Upravit')->setIcon('pencil')->setCustomRender($this->gridHrefRender);
     $grid->addActionHref('delete', 'Smazat')->setIcon('trash')->setCustomRender($this->gridHrefRender)->setConfirm(function ($item) {
         return "Opravdu chcete smazat slečnu se jménem {$item['firstname']} {$item['surname']}?";
     });
     $grid->setExport();
 }
Exemple #3
0
 protected function createComponentGrid($name)
 {
     $grid = new Grid($this, $name);
     $fluent = $this->database->select('u.*, c.title AS country')->from('[user] u')->join('[country] c')->on('u.country_code = c.code');
     $grid->model = $fluent;
     $grid->addColumnText('firstname', 'Firstname')->setFilterText()->setSuggestion();
     $grid->addColumnText('surname', 'Surname')->setSortable()->setFilterText()->setSuggestion();
     $grid->addColumnText('gender', 'Gender')->setSortable()->cellPrototype->class[] = 'center';
     $grid->addColumnDate('birthday', 'Birthday', \Grido\Components\Columns\Date::FORMAT_TEXT)->setSortable()->setFilterDate()->setCondition($grid->birthdayFilterCondition);
     $grid->getColumn('birthday')->cellPrototype->class[] = 'center';
     $customRender = function ($item) {
         $baseUri = $this->getBaseUri();
         $img = Html::el('img')->src("{$baseUri}/img/flags/{$item->country_code}.gif");
         return "{$img} {$item->country}";
     };
     $grid->addColumnText('country', 'Country')->setSortable()->setCustomRender($customRender)->setFilterText()->setColumn('c.title')->setSuggestion('title');
     $grid->addColumnText('card', 'Card')->setSortable()->setColumn('cctype')->setReplacement(array('MasterCard' => Html::el('b')->setText('MasterCard')))->cellPrototype->class[] = 'center';
     $grid->addColumnEmail('emailaddress', 'Email')->setSortable()->setFilterText();
     $grid->getColumn('emailaddress')->cellPrototype->class[] = 'center';
     $grid->addColumnText('centimeters', 'Height')->setSortable()->setFilterNumber();
     $grid->getColumn('centimeters')->cellPrototype->class[] = 'center';
     $grid->addFilterSelect('gender', 'Gender', array('' => '', 'female' => 'female', 'male' => 'male'));
     $grid->addFilterSelect('card', 'Card', array('' => '', 'MasterCard' => 'MasterCard', 'Visa' => 'Visa'))->setColumn('cctype');
     $grid->addFilterCheck('preferred', 'Only preferred girls :)')->setCondition(array(TRUE => array(array('gender', 'AND', 'centimeters'), array('= ?', '>= ?'), array('female', 170))));
     $grid->addActionHref('edit', 'Edit')->setIcon('pencil');
     $grid->addActionHref('delete', 'Delete')->setIcon('trash')->setConfirm(function ($item) {
         return "Are you sure you want to delete {$item->firstname} {$item->surname}?";
     });
     $operation = array('print' => 'Print', 'delete' => 'Delete');
     $grid->setOperation($operation, $this->handleOperations)->setConfirm('delete', 'Are you sure you want to delete %i items?');
     $grid->filterRenderType = $this->filterRenderType;
     $grid->setExport();
     return $grid;
 }
 protected function createComponentGrid($name)
 {
     $grid = new Grid($this, $name);
     $grid->model = $this->database->table('user');
     $grid->addColumnText('firstname', 'Firstname')->setFilterText()->setSuggestion();
     $grid->addColumnText('surname', 'Surname')->setSortable()->setFilterText()->setSuggestion();
     $grid->addColumnText('gender', 'Gender')->setSortable()->cellPrototype->class[] = 'center';
     $grid->addColumnDate('birthday', 'Birthday', \Grido\Components\Columns\Date::FORMAT_TEXT)->setSortable()->setFilterDate()->setCondition($grid->birthdayFilterCondition);
     $grid->getColumn('birthday')->cellPrototype->class[] = 'center';
     $templatePath = "{$this->context->parameters['appDir']}/templates/{$this->name}";
     $renderer = function ($row) {
         return $row->country->title;
     };
     $grid->addColumnText('country', 'Country')->setSortable()->setColumn('country.title')->setCustomRender("{$templatePath}/grid.country.latte")->setCustomRenderExport($renderer)->setFilterText()->setSuggestion($renderer);
     $grid->addColumnText('card', 'Card')->setSortable()->setColumn('cctype')->setReplacement(array('MasterCard' => Html::el('b')->setText('MasterCard')))->cellPrototype->class[] = 'center';
     $grid->addColumnEmail('emailaddress', 'Email')->setSortable()->setFilterText();
     $grid->getColumn('emailaddress')->cellPrototype->class[] = 'center';
     $grid->addColumnText('centimeters', 'Height')->setSortable()->setFilterNumber();
     $grid->getColumn('centimeters')->cellPrototype->class[] = 'center';
     $grid->addFilterSelect('gender', 'Gender', array('' => '', 'female' => 'female', 'male' => 'male'));
     $grid->addFilterSelect('card', 'Card', array('' => '', 'MasterCard' => 'MasterCard', 'Visa' => 'Visa'))->setColumn('cctype');
     $grid->addFilterCheck('preferred', 'Only preferred girls :)')->setCondition(array(TRUE => array(array('gender', 'AND', 'centimeters'), array('= ?', '>= ?'), array('female', 170))));
     $grid->addActionHref('edit', 'Edit')->setIcon('pencil');
     $grid->addActionHref('delete', 'Delete')->setIcon('trash')->setConfirm(function ($item) {
         return "Are you sure you want to delete {$item->firstname} {$item->surname}?";
     });
     $operation = array('print' => 'Print', 'delete' => 'Delete');
     $grid->setOperation($operation, $this->handleOperations)->setConfirm('delete', 'Are you sure you want to delete %i items?');
     $grid->filterRenderType = $this->filterRenderType;
     $grid->setExport();
 }
Exemple #5
0
 public function run()
 {
     $grid = new Grid($this->getParent(), $this->name);
     $grid->model = $this->dibiSource;
     $grid->setPrimaryKey($this->pk);
     foreach ($this->columns as $name => $title) {
         $gridColumn = $grid->addColumnText($name, $title)->setFilterText()->setSuggestion();
         if (isset($this->callBack[$name])) {
             $gridColumn->setColumn($this->callBack[$name]);
         }
     }
     foreach ($this->buttons as $action => $title) {
         $grid->addActionHref($action, $title, $this->presenter . ":" . $action);
     }
     $grid->setExport();
     $this->setGrid($grid);
 }
 /**
  * Only columns and operations.
  * @param string $name
  * @return Grid
  */
 private function baseGrid($name)
 {
     $grid = new Grid($this, $name);
     $grid->translator->lang = 'cs';
     $grid->defaultPerPage = 4;
     $fluent = $this->database->select('u.*, c.title AS country')->from('[user] u')->join('[country] c')->on('u.country_code = c.code');
     $grid->model = $fluent;
     $grid->addColumnText('firstname', 'Firstname')->setSortable()->headerPrototype->class[] = 'center';
     $grid->getColumn('firstname')->cellPrototype->class[] = 'center';
     $grid->addColumnText('surname', 'Surname')->setSortable()->headerPrototype->class[] = 'center';
     $grid->getColumn('surname')->cellPrototype->class[] = 'center';
     $grid->addColumnText('gender', 'Gender')->setSortable()->headerPrototype->class[] = 'center';
     $grid->getColumn('gender')->cellPrototype->class[] = 'center';
     $grid->addColumnDate('birthday', 'Birthday', \Grido\Components\Columns\Date::FORMAT_TEXT)->setSortable()->headerPrototype->class[] = 'center';
     $grid->getColumn('birthday')->cellPrototype->class[] = 'center';
     $grid->addColumnText('country', 'Country')->setSortable()->setCustomRender(function ($item) {
         $baseUri = $this->getBaseUri();
         $img = Html::el('img')->src("{$baseUri}/img/flags/{$item->country_code}.gif");
         return "{$img} {$item->country}";
     })->headerPrototype->class[] = 'center';
     $grid->getColumn('country')->cellPrototype->class[] = 'center';
     $grid->addColumnText('city', 'City')->setSortable()->headerPrototype->class[] = 'center';
     $grid->getColumn('city')->cellPrototype->class[] = 'center';
     $grid->addColumnText('zip', 'ZIP')->setColumn('zipcode')->setSortable()->headerPrototype->class[] = 'center';
     $grid->getColumn('zip')->cellPrototype->class[] = 'center';
     $grid->addColumnText('phone', 'Phone')->setColumn('telephonenumber')->setSortable()->headerPrototype->class[] = 'center';
     $grid->getColumn('phone')->cellPrototype->class[] = 'center';
     $grid->addColumnEmail('email', 'Email')->setColumn('emailaddress')->setSortable()->headerPrototype->class[] = 'center';
     $grid->getColumn('email')->cellPrototype->class[] = 'center';
     $grid->addColumnText('card', 'Card')->setSortable()->setColumn('cctype')->setReplacement(array('MasterCard' => Html::el('b')->setText('MasterCard')))->headerPrototype->class[] = 'center';
     $grid->getColumn('card')->cellPrototype->class[] = 'center';
     $grid->addColumnText('height', 'Height')->setColumn('centimeters')->setSortable()->headerPrototype->class[] = 'center';
     $grid->getColumn('height')->cellPrototype->class[] = 'center';
     $operation = array('print' => 'Print', 'delete' => 'Delete');
     $grid->setOperation($operation, $this->handleOperations)->setConfirm('delete', 'Are you sure you want to delete %i items?');
     $grid->setExport();
     return $grid;
 }
 protected function createComponentGrid($name)
 {
     $grid = new Grid($this, $name);
     $grid->model = $this->database->table('user');
     $grid->setEditableColumns(function ($id, $newValue, $oldValue, $column) {
         //do update ... and return result
         return TRUE;
     });
     $grid->addColumnText('firstname', 'Firstname')->setFilterText()->setSuggestion();
     $grid->addColumnText('surname', 'Surname')->setSortable()->setFilterText()->setSuggestion();
     $grid->getColumn('surname')->getEditableControl()->setRequired('Surname is required.');
     $genderList = array('female' => 'female', 'male' => 'male');
     $grid->addColumnText('gender', 'Gender')->setEditableControl(new \Nette\Forms\Controls\SelectBox(NULL, $genderList))->setSortable()->cellPrototype->class[] = 'center';
     $grid->addColumnDate('birthday', 'Birthday', \Grido\Components\Columns\Date::FORMAT_TEXT)->setSortable()->setFilterDate()->setCondition($grid->birthdayFilterCondition);
     $grid->getColumn('birthday')->cellPrototype->class[] = 'center';
     $grid->getColumn('birthday')->getEditableControl()->controlPrototype->class[] = 'date';
     $grid->getColumn('birthday')->setEditableValueCallback(function ($row, $column) {
         return date($column::FORMAT_DATE, strtotime($row->birthday));
     });
     $cardList = array('MasterCard' => 'MasterCard', 'Visa' => 'Visa');
     $grid->addColumnText('card', 'Card')->setSortable()->setColumn('cctype')->setReplacement(array('MasterCard' => Html::el('b')->setText('MasterCard')))->setEditableControl(new \Nette\Forms\Controls\SelectBox(NULL, $cardList))->cellPrototype->class[] = 'center';
     $grid->addColumnEmail('emailaddress', 'Email')->setSortable()->setFilterText();
     $grid->getColumn('emailaddress')->cellPrototype->class[] = 'center';
     $grid->addColumnText('centimeters', 'Height')->setSortable()->setFilterNumber();
     $grid->getColumn('centimeters')->cellPrototype->class[] = 'center';
     $grid->getColumn('centimeters')->getEditableControl()->controlPrototype->type = 'number';
     $grid->addFilterSelect('gender', 'Gender', array('' => '') + $genderList);
     $grid->addFilterSelect('card', 'Card', array('' => '') + $cardList)->setColumn('cctype');
     $grid->addActionHref('edit', 'Edit')->setIcon('pencil');
     $grid->addActionHref('delete', 'Delete')->setIcon('trash')->setConfirm(function ($item) {
         return "Are you sure you want to delete {$item->firstname} {$item->surname}?";
     });
     $operation = array('print' => 'Print', 'delete' => 'Delete');
     $grid->setOperation($operation, $this->handleOperations)->setConfirm('delete', 'Are you sure you want to delete %i items?');
     $grid->filterRenderType = $this->filterRenderType;
     $grid->setExport();
 }