protected function getDataRows() { if (TreeView::EXPANDED === $this->mode) { if (null === $this->dataRows) { $this->dataRows = $this->dataSource->fetchAssoc($this->primaryKey); } return $this->dataRows; } else { return parent::getDataRows(); } }
public function render() { $this->getPaginator()->itemCount = $this->count; $this->template->results = $this->count; $this->template->columns = $this['columns']->components; $this->template->buttons = $this['buttons']->components; $this->template->subGrids = $this['subGrids']->components; $this->template->paginate = $this->paginate; $this->template->colsCount = $this->getColsCount(); $this->template->new = $this->new; $rows = $this->dataSource->getData(); $this->template->rows = $rows; $this->template->primaryKey = $this->primaryKey; if ($this->hasActiveRowForm()) { $row = $rows[$this->activeRowForm]; foreach ($row as $name => $value) { if ($this->columnExists($name) && !empty($this['columns']->components[$name]->formRenderer)) { $row[$name] = call_user_func($this['columns']->components[$name]->formRenderer, $row); } if (isset($this['gridForm'][$this->name]['rowForm'][$name])) { $input = $this['gridForm'][$this->name]['rowForm'][$name]; if ($input instanceof \Nette\Forms\Controls\SelectBox) { $items = $this['gridForm'][$this->name]['rowForm'][$name]->getItems(); if (in_array($row[$name], $items)) { $row[$name] = array_search($row[$name], $items); } } } } $this['gridForm'][$this->name]['rowForm']->setDefaults($row); $this['gridForm'][$this->name]['rowForm']->addHidden($this->primaryKey, $this->activeRowForm); } if ($this->paginate) { $this->template->viewedFrom = ($this->getPaginator()->getPage() - 1) * $this->perPage + 1; $this->template->viewedTo = $this->getPaginator()->getLength() + ($this->getPaginator()->getPage() - 1) * $this->perPage; } $templatePath = !empty($this->templatePath) ? $this->templatePath : __DIR__ . "/templates/grid.latte"; $this->template->setFile($templatePath); $this->template->render(); }
private function sort(IDataSource $dataSource) { if ($this->sorting === NULL) { $this->sorting = $this->defaultSorting; } if ($this->sorting === NULL) { return; } // Check column list($column) = $this->sorting; if ($column != $this->primaryKey) { $column = $this['columns'][$column]; if (!$column->isSortable()) { throw new InvalidArgumentException("Column '{$column->name}' is not sortable"); } $column->setSorting(); } $dataSource->sort($this->sorting); }