/**
* 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->template->setTranslator($this->getTranslator());
/**
* Invoke some 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->sort, $this->assableFilters()]);
}
foreach ($items as $item) {
$rows[] = new Row($this, $item, $this->getPrimaryKey());
}
if ($this->isTreeView()) {
$this->template->tree_view_has_children_column = $this->tree_view_has_children_column;
}
$this->template->rows = $rows;
$this->template->columns = $this->columns;
$this->template->actions = $this->actions;
$this->template->exports = $this->exports;
$this->template->filters = $this->filters;
$this->template->filter_active = $this->isFilterActive();
$this->template->original_template = $this->getOriginalTemplateFile();
$this->template->icon_prefix = static::$icon_prefix;
$this->template->items_detail = $this->items_detail;
/**
* Walkaround for Latte (does not know $form in snippet in {form} etc)
*/
$this->template->filter = $this['filter'];
/**
* Set template file and render it
*/
$this->template->setFile($this->getTemplateFile())->render();
}