setRowCallback() public method

Callback returns tr html element; function($row, Html $tr).
public setRowCallback ( $callback ) : Grid
$callback
return Grid
 /**
  * Builds listing grid
  *
  * @param string|null $name
  * @return Grid
  * @throws \Grido\Exception
  */
 public function createComponentDataGrid($name = NULL)
 {
     $data = $this->generateDataForGrid();
     $dataGrid = new Grid($this, $name);
     $dataGrid->setRowCallback(function ($row, $tr) {
         /** @var Nette\Utils\Html $tr */
         if (empty($row['translation'])) {
             $tr->attrs['class'][] = 'untranslated';
         }
         return $tr;
     });
     $dataGrid->setFilterRenderType(Filter::RENDER_INNER);
     $dataGrid->setModel(new ArraySource($data));
     $dataGrid->addActionHref('remove', 'Remove', 'remove');
     $dataGrid->setDefaultSort(array('translation' => 'ASC'));
     // Columns
     $catalogueColumn = $dataGrid->addColumnText('catalogue', 'Catalogue');
     $catalogueColumn->setCustomRender(function ($values) {
         return ucfirst($values['catalogue']);
     });
     $catalogueColumn->setFilterSelect($this->getCataloguesInModel($data));
     $catalogueColumn->setSortable();
     $dataGrid->addColumnText('id', 'Code')->setSortable()->setFilterText();
     $translationColumn = $dataGrid->addColumnText('translation', 'Translation');
     $translationColumn->setFilterText();
     $translationColumn->setCustomRender(function ($values) {
         $el = Nette\Utils\Html::el('textarea');
         $el->addAttributes(array('type' => 'text', 'class' => 'text', 'rows' => 1, 'data-translation-control-change-url' => $this->link('saveTranslation!', array('catalogue' => $values['catalogue'], 'code' => $values['id'], 'language' => $this->locale))));
         $el->add(str_replace('|', "|\n", $values['translation']));
         return $el;
     });
     return $dataGrid;
 }
Example #2
0
 /**
  * @param $name
  * @return Grid
  */
 protected function createComponentGrid($name)
 {
     $grid = new Grid($this, $name);
     $grid->translator->lang = 'cs';
     $fluent = $this->pagesRepository->getAll();
     $pages = [];
     foreach ($fluent as $pageRow) {
         $pages[$pageRow->id] = $pageRow;
     }
     if (isset($grid->model)) {
         $grid->model = $fluent;
     }
     $grid->addColumnNumber('id', 'ID');
     $header = $grid->getColumn('id')->headerPrototype;
     $header->style['width'] = '0.5%';
     $grid->addColumnText('name', 'Název')->setFilterText()->setSuggestion();
     $grid->getColumn('name')->headerPrototype->style['width'] = '80%';
     $grid->addColumnText('active', 'Aktivní')->setCustomRender(function ($item) {
         if ($item->active == 0) {
             $i = Html::el('i', ['class' => 'glyphicon glyphicon-thumbs-down']);
             $el = Html::el('a', ['class' => 'btn btn-danger btn-xs btn-mini ajax'])->href($this->presenter->link("active!", $item->id))->setHtml($i);
         } else {
             $i = Html::el('i', ['class' => 'glyphicon glyphicon-thumbs-up']);
             $el = Html::el('a', ['class' => 'btn btn-success btn-xs btn-mini ajax'])->href($this->presenter->link("active!", $item->id))->setHtml($i);
         }
         return $el;
     })->cellPrototype->class[] = 'center';
     $grid->addColumnText('inMenu', 'Top menu')->setCustomRender(function ($item) {
         $menuItems = (array) json_decode($item->inMenu);
         if (!in_array('topMenu', $menuItems)) {
             $i = Html::el('i', ['class' => 'glyphicon glyphicon-thumbs-down']);
             $el = Html::el('a', ['class' => 'btn btn-danger btn-xs btn-mini ajax'])->href($this->presenter->link("inTopMenu!", $item->id))->setHtml($i);
         } else {
             $i = Html::el('i', ['class' => 'glyphicon glyphicon-thumbs-up']);
             $el = Html::el('a', ['class' => 'btn btn-success btn-xs btn-mini ajax'])->href($this->presenter->link("inTopMenu!", $item->id))->setHtml($i);
         }
         return $el;
     })->cellPrototype->class[] = 'center';
     $grid->addActionHref('edit', '')->setIcon('pencil');
     $grid->addActionEvent('delete', '')->setCustomRender(function ($item) {
         if ($item->parent === 0 || $item->rgt - $item->lft > 1) {
             $i = Html::el('i', ['class' => 'fa']);
             $el = Html::el('span', ['class' => 'btn btn-xs btn-mini'])->setHtml($i);
         } else {
             $i = Html::el('i', ['class' => 'fa fa-trash']);
             $el = Html::el('a', ['class' => 'btn btn-default btn-xs btn-mini ajax', 'data-grido-confirm' => "Opravdu chcete tuto položku odstranit?"])->href($this->presenter->link("delete!", $item->id))->setHtml($i);
         }
         return $el;
     });
     $grid->addActionEvent('moveup', '')->setCustomRender(function ($item) use($pages) {
         $first = $item->parent == 0 || $item->lft - 1 == $pages[$item->parent]['lft'];
         if ($first) {
             $i = Html::el('i', ['class' => 'fa']);
             $el = Html::el('span', ['class' => 'btn btn-xs btn-mini'])->setHtml($i);
         } else {
             $i = Html::el('i', ['class' => 'fa fa-arrow-up']);
             $el = Html::el('a', ['class' => 'btn btn-default btn-xs btn-mini ajax'])->href($this->presenter->link("move!", $item->id, self::UP))->setHtml($i);
         }
         return $el;
     });
     $grid->addActionEvent('movedn', '')->setCustomRender(function ($item) use($pages) {
         $last = $item->parent == 0 || $item->rgt + 1 == $pages[$item->parent]['rgt'];
         if ($last) {
             $i = Html::el('i', ['class' => 'fa']);
             $el = Html::el('span', ['class' => 'btn btn-xs btn-mini'])->setHtml($i);
         } else {
             $i = Html::el('i', ['class' => 'fa fa-arrow-down']);
             $el = Html::el('a', ['class' => 'btn btn-default btn-xs btn-mini ajax'])->href($this->presenter->link("move!", $item->id, self::DN))->setHtml($i);
         }
         return $el;
     });
     $grid->addActionHref('add', '')->setIcon('plus');
     $grid->setDefaultSort(['lft' => 'ASC']);
     $grid->setRememberState(TRUE);
     $grid->setPrimaryKey('id');
     $grid->setDefaultPerPage(50);
     $grid->setRowCallback(function ($item, $tr) {
         $tr->class[] = "level_{$item->level}";
         return $tr;
     });
     $grid->filterRenderType = $this->filterRenderType;
     $grid->setExport();
     return $grid;
 }