Inheritance: extends Nette\Object
Beispiel #1
0
 /**
  * Get value from column using Row::getValue() or custom callback
  * @param Row    	    $row
  * @param Column\Column $column
  * @return bool
  */
 private function getValue(Row $row, $column)
 {
     if (!$this->rowCallback) {
         return $row->getValue($column->getColumn());
     }
     return call_user_func_array($this->rowCallback, [$row->getItem(), $column->getColumn()]);
 }
Beispiel #2
0
 /**
  * Find selected option for current item/row
  * @param  Row    $row
  * @return Option|NULL
  */
 public function getCurrentOption(Row $row)
 {
     foreach ($this->getOptions() as $option) {
         if ($option->getValue() == $row->getValue($this->getColumn())) {
             return $option;
         }
     }
     return NULL;
 }
Beispiel #3
0
 /**
  * Get row item params (E.g. action may be called id => $item->id, name => $item->name, ...)
  * @param  Row   $row
  * @return array
  */
 protected function getItemParams(Row $row)
 {
     $return = [];
     foreach ($this->params as $param_name => $param) {
         $return[is_string($param_name) ? $param_name : $param] = $row->getValue($param);
     }
     return $return;
 }
Beispiel #4
0
 /**
  * Apply replacements
  * @param  Row   $row
  * @return array
  */
 public function applyReplacements(Row $row)
 {
     $value = $row->getValue($this->column);
     if ((is_scalar($value) || is_null($value)) && isset($this->replacements[$value])) {
         return [TRUE, $this->replacements[$value]];
     }
     return [FALSE, NULL];
 }
Beispiel #5
0
 /**
  * Check whether given property is string or callable
  * 	in that case call callback and check property and return it
  * @param  Row                  $row
  * @param  string|callable|null $property
  * @param  string               $name
  * @return string
  * @throws DataGridException
  */
 public function getPropertyStringOrCallableGetString(Row $row, $property, $name)
 {
     /**
      * String
      */
     if (is_string($property)) {
         return $property;
     }
     /**
      * Callable
      */
     if (is_callable($property)) {
         $value = call_user_func($property, $row->getItem());
         if (!is_string($value)) {
             throw new DataGridException("Action {$name} callback has to return a string");
         }
         return $value;
     }
     return $property;
 }
Beispiel #6
0
 /**
  * Get row item params (E.g. action may be called id => $item->id, name => $item->name, ...)
  * @param  Row   $row
  * @param  array $params_list
  * @return array
  */
 protected function getItemParams(Row $row, array $params_list)
 {
     $return = [];
     foreach ($params_list as $param_name => $param) {
         $return[is_string($param_name) ? $param_name : $param] = $row->getValue($param);
     }
     return $return;
 }
Beispiel #7
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();
 }
Beispiel #8
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->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();
 }
Beispiel #9
0
 /**
  * @param Row $row
  * @return bool
  */
 public function shouldBeRendered(Row $row)
 {
     $condition = $this->render_condition_callback;
     return $condition ? $condition($row->getItem()) : TRUE;
 }