Example #1
0
 /**
  * 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();
 }
Example #2
0
 /**
  * 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 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(), new Sorting($this->sort, $this->sort_callback), $this->assableFilters()]);
     }
     $callback = $this->rowCallback ?: NULL;
     foreach ($items as $item) {
         $rows[] = $row = new Row($this, $item, $this->getPrimaryKey());
         if ($callback) {
             $callback($item, $row->getControl());
         }
     }
     if ($this->isTreeView()) {
         $this->template->add('tree_view_has_children_column', $this->tree_view_has_children_column);
     }
     $this->template->add('rows', $rows);
     $this->template->add('columns', $this->getColumns());
     $this->template->add('actions', $this->actions);
     $this->template->add('exports', $this->exports);
     $this->template->add('filters', $this->filters);
     $this->template->add('filter_active', $this->isFilterActive());
     $this->template->add('original_template', $this->getOriginalTemplateFile());
     $this->template->add('icon_prefix', static::$icon_prefix);
     $this->template->add('items_detail', $this->items_detail);
     $this->template->add('columns_visibility', $this->columns_visibility);
     $this->template->add('inlineEdit', $this->inlineEdit);
     $this->template->add('inlineAdd', $this->inlineAdd);
     /**
      * Walkaround for Latte (does not know $form in snippet in {form} etc)
      */
     $this->template->add('filter', $this['filter']);
     /**
      * Set template file and render it
      */
     $this->template->setFile($this->getTemplateFile());
     $this->template->render();
 }
Example #3
0
 /**
  * @return DataSource\IDataSource|NULL
  */
 public function getDataSource()
 {
     if (!$this->dataModel) {
         return NULL;
     }
     return $this->dataModel->getDataSource();
 }