/** * Render template * @return void */ public function render() { /** * Check whether datagrid has set some columns, initiated data source, etc */ if (!$this->dataModel instanceof DataModel) { throw new DataGridException('You have to set a data source first.'); } if (empty($this->columns)) { throw new DataGridException('You have to add at least one column.'); } $this->getTemplate()->setTranslator($this->getTranslator()); /** * Invoke possible events */ $this->onRender($this); /** * Prepare data for rendering (datagrid may render just one item) */ $rows = []; if (!empty($this->redraw_item)) { $items = $this->dataModel->filterRow($this->redraw_item); } else { $items = Nette\Utils\Callback::invokeArgs([$this->dataModel, 'filterData'], [$this->getPaginator(), $this->createSorting($this->sort, $this->sort_callback), $this->assableFilters()]); } $callback = $this->rowCallback ?: NULL; $hasGroupActionOnRows = FALSE; foreach ($items as $item) { $rows[] = $row = new Row($this, $item, $this->getPrimaryKey()); if (!$hasGroupActionOnRows && $row->hasGroupAction()) { $hasGroupActionOnRows = TRUE; } if ($callback) { $callback($item, $row->getControl()); } /** * Walkaround for item snippet - snippet is the <tr> element and its class has to be also updated */ if (!empty($this->redraw_item)) { $this->getPresenter()->payload->_datagrid_redraw_item_class = $row->getControlClass(); $this->getPresenter()->payload->_datagrid_redraw_item_id = $row->getId(); } } if ($hasGroupActionOnRows) { $hasGroupActionOnRows = $this->hasGroupActions(); } if ($this->isTreeView()) { $this->getTemplate()->add('tree_view_has_children_column', $this->tree_view_has_children_column); } $this->getTemplate()->add('rows', $rows); $this->getTemplate()->add('columns', $this->getColumns()); $this->getTemplate()->add('actions', $this->actions); $this->getTemplate()->add('exports', $this->exports); $this->getTemplate()->add('filters', $this->filters); $this->getTemplate()->add('toolbar_buttons', $this->toolbar_buttons); $this->getTemplate()->add('aggregation_functions', $this->getAggregationFunctions()); $this->getTemplate()->add('multiple_aggregation_function', $this->getMultipleAggregationFunction()); $this->getTemplate()->add('filter_active', $this->isFilterActive()); $this->getTemplate()->add('original_template', $this->getOriginalTemplateFile()); //$this->getTemplate()->add('icon_prefix', static::$icon_prefix); $this->getTemplate()->icon_prefix = static::$icon_prefix; $this->getTemplate()->add('items_detail', $this->items_detail); $this->getTemplate()->add('columns_visibility', $this->getColumnsVisibility()); $this->getTemplate()->add('columnsSummary', $this->columnsSummary); $this->getTemplate()->add('inlineEdit', $this->inlineEdit); $this->getTemplate()->add('inlineAdd', $this->inlineAdd); $this->getTemplate()->add('hasGroupActionOnRows', $hasGroupActionOnRows); /** * Walkaround for Latte (does not know $form in snippet in {form} etc) */ $this->getTemplate()->add('filter', $this['filter']); /** * Set template file and render it */ $this->getTemplate()->setFile($this->getTemplateFile()); $this->getTemplate()->render(); }