/** * Render row item into template * @param Row $row * @return mixed */ public function render(Row $row) { /** * Renderer function may be used */ if ($renderer = $this->getRenderer()) { if (!$renderer->getConditionCallback()) { return call_user_func_array($renderer->getCallback(), [$row->getItem()]); } if (call_user_func_array($this->getRenderer(), [$row->getItem()])) { return call_user_func_array($renderer->getCallback(), [$row->getItem()]); } } $a = Html::el('a')->href($this->grid->getPresenter()->link($this->href, $this->getItemParams($row))); if ($this->icon) { $a->add(Html::el('span')->class(DataGrid::$icon_prefix . $this->icon)); if (strlen($this->name)) { $a->add(' '); } } $a->add($this->name); if ($this->title) { $a->title($this->title); } if ($this->class) { $a->class($this->class); } if ($confirm = $this->getConfirm($row)) { $a->data('confirm', $confirm); } return $a; }
/** * Call export callback * @param array $data * @param DataGrid $grid * @return void */ public function invoke(array $data, DataGrid $grid) { $columns = $this->getColumns() ?: $grid->getColumns(); $csv_data_model = new CsvDataModel($data, $columns); $grid->getPresenter()->sendResponse(new CSVResponse($csv_data_model->getSimpleData(), $this->name)); exit(0); }
/** * @param Row $row */ public function add(Row $row) { foreach ($this->summary as $key => $sum) { $column = $this->datagrid->getColumn($key); $value = $this->getValue($row, $column); $this->summary[$key] += $value; } }
/** * Call export callback * @param array $data * @param DataGrid $grid * @return void */ public function invoke(array $data, DataGrid $grid) { $columns = $this->getColumns() ?: $grid->getColumns(); $csv_data_model = new CsvDataModel($data, $columns, $grid->getTranslator()); if ($grid->getPresenter() instanceof Nette\Application\UI\Presenter) { $grid->getPresenter()->sendResponse(new CSVResponse($csv_data_model->getSimpleData(), $this->name, $this->output_encoding, $this->delimiter)); exit(0); } }
/** * Render export button * @return Html */ public function render() { $a = Html::el('a', ['class' => [$this->class], 'title' => $this->grid->getTranslator()->translate($this->getTitle()), 'href' => $this->link]); $this->tryAddIcon($a, $this->getIcon(), $this->grid->getTranslator()->translate($this->getTitle())); $a->addText($this->grid->getTranslator()->translate($this->text)); if ($this->isAjax()) { $a->class[] = 'ajax'; } return $a; }
/** * Create link to custom destination * @param DataGrid $grid * @param string $href * @param array $params * @return string * @throws DataGridHasToBeAttachedToPresenterComponentException * @throws \InvalidArgumentException */ protected function createLink(DataGrid $grid, $href, $params) { try { $parent = $grid->getParent(); return $parent->link($href, $params); } catch (DataGridHasToBeAttachedToPresenterComponentException $e) { $parent = $grid->getPresenter(); } catch (\InvalidArgumentException $e) { $parent = $grid->getPresenter(); } return $parent->link($href, $params); }
/** * Render row item detail button * @param Row $row * @return Html */ public function renderButton($row) { $a = Html::el('a')->href($this->grid->link('getItemDetail!', ['id' => $row->getId()]))->data('toggle-detail', $row->getId())->data('toggle-detail-grid', $this->grid->getName()); $this->tryAddIcon($a, $this->getIcon(), $this->getText()); $a->addText($this->text); if ($this->title) { $a->title($this->grid->getTranslator()->translate($this->title)); } if ($this->class) { $a->class($this->class); } return $a; }
/** * Render toolbar button * @return Html */ public function renderButton() { $link = $this->createLink($this->grid, $this->href, $this->params); $a = Html::el('a')->href($link); $this->tryAddIcon($a, $this->getIcon(), $this->getText()); $a->addText($this->grid->getTranslator()->translate($this->text)); if ($this->title) { $a->title($this->grid->getTranslator()->translate($this->title)); } if ($this->class) { $a->class($this->class); } return $a; }
/** * @param string $key * @param string $name * @param string $href * @param array|null $params * @return static */ public function addAction($key, $name, $href = NULL, array $params = NULL) { if (isset($this->actions[$key])) { throw new DataGridException("There is already action at key [{$key}] defined for MultiAction."); } $href = $href ?: $key; if (NULL === $params) { $params = [$this->grid->getPrimaryKey()]; } $action = new Action($this->grid, $href, $name, $params); $action->setClass(''); $this->actions[$key] = $action; return $this; }
/** * Generates control's HTML element. * @param string * @return Nette\Utils\Html */ public function getControl($caption = NULL) { $el = parent::getControl(''); $el->type = 'submit'; $el->class = $this->getClass(); if ($this->getIcon()) { $el->addHtml(Html::el('span')->class(DataGrid::$icon_prefix . $this->getIcon())); if (strlen($this->getText())) { $el->addHtml(' '); } } $el->addText($this->grid->getTranslator()->translate($this->getText())); return $el; }
/** * @param string $key * @param Column\Column $column * @return void */ public function applyColumnCallback($key, Column\Column $column) { $callback = $this->datagrid->getColumnCallback($key); if ($callback !== NULL) { call_user_func($callback, $column, $this->getItem()); } return $column; }
/** * Render row item detail button * @param Row $row * @return Html */ public function renderButton($row) { $a = Html::el('a')->href($this->grid->link('getItemDetail!', ['id' => $row->getId()]))->data('toggle-detail', $row->getId())->data('toggle-detail-grid', $this->grid->getName()); if ($this->icon) { $a->add(Html::el('span')->class(DataGrid::$icon_prefix . $this->icon)); if (strlen($this->text)) { $a->add(' '); } } $a->add($this->text); if ($this->title) { $a->title($this->title); } if ($this->class) { $a->class($this->class); } return $a; }
/** * @param Nette\Forms\Controls\BaseControl $input * @return Nette\Forms\Controls\BaseControl */ protected function addAttributes($input) { if ($this->grid->hasAutoSubmit()) { $input->setAttribute('data-autosubmit', TRUE); } else { $input->setAttribute('data-datagrid-manualsubmit', TRUE); } foreach ($this->attributes as $attribute) { $input->setAttribute($attribute[0], $attribute[1]); } return $input; }
/** * Render row item detail button * @param Row $row * @return Html */ public function renderButton($row) { $a = Html::el('a')->href($this->grid->link('inlineEdit!', ['id' => $row->getId()])); $this->tryAddIcon($a, $this->getIcon(), $this->getText()); $a->add($this->text); if ($this->title) { $a->title($this->title); } if ($this->class) { $a->class($this->class); } return $a; }
/** * Render row item detail button * @return Html */ public function renderButtonAdd() { $a = Html::el('a')->data('datagrid-toggle-inline-add', TRUE); $this->tryAddIcon($a, $this->getIcon(), $this->getText()); $a->addText($this->text); if ($this->title) { $a->title($this->grid->getTranslator()->translate($this->title)); } if ($this->class) { $a->class($this->class); } return $a; }
/** * Render item detail button * @param mixed $item * @return Html */ public function renderButton($item) { if (is_object($item)) { $id_value = $item->{$this->grid->getPrimaryKey()}; } else { $id_value = $item[$this->grid->getPrimaryKey()]; } $a = Html::el('a')->href($this->grid->link('getItemDetail!', ['id' => $id_value]))->data('toggle-detail', $id_value)->data('toggle-detail-grid', $this->grid->getName()); if ($this->icon) { $a->add(Html::el('span')->class(DataGrid::$icon_prefix . $this->icon)); if (strlen($this->text)) { $a->add(' '); } } $a->add($this->text); if ($this->title) { $a->title($this->title); } if ($this->class) { $a->class($this->class); } return $a; }
/** * Render row item into template * @param Row $row * @return mixed */ public function render(Row $row) { /** * Renderer function may be used */ if ($renderer = $this->getRenderer()) { if (!$renderer->getConditionCallback()) { return call_user_func_array($renderer->getCallback(), [$row->getItem()]); } if (call_user_func_array($renderer->getConditionCallback(), [$row->getItem()])) { return call_user_func_array($renderer->getCallback(), [$row->getItem()]); } } $value = parent::render($row); $href = $this->grid->getPresenter()->link($this->href, $this->getItemParams($row)); $a = Html::el('a')->href($href)->setText($value); if ($this->title) { $a->title($this->title); } if ($this->class) { $a->class($this->class); } return $a; }
/** * Pass "sub"-form submission forward to custom submit function * @param Form $form * @return void */ public function submitted(Form $form) { if (!isset($form['group_action']['submit']) || !$form['group_action']['submit']->isSubmittedBy()) { return; } $values = $form->getValues(); $values = $values['group_action']; if ($values->group_action === 0 || is_null($values->group_action)) { return; } /** * @todo Define items IDs */ $http_ids = $form->getHttpData(Form::DATA_LINE | Form::DATA_KEYS, strtolower($this->datagrid->getName()) . '_group_action_item[]'); $ids = array_keys($http_ids); $id = $values->group_action; $this->group_actions[$id]->onSelect($ids, isset($values->{$id}) ? $values->{$id} : NULL); $form['group_action']['group_action']->setValue(NULL); }
/** * @return DataGrid */ public function create() { $grid = new DataGrid(); $grid->setTranslator($this->translator); return $grid; }
/** * Translator helper * @param string $message * @return string */ protected function translate($message) { return $this->grid->getTranslator()->translate($message); }
/** * @param string|null $column * @param string|null $name_second * @return Ublaboo\DataGrid\Filter\FilterDateRange */ public function setFilterDateRange($column = NULL, $name_second = '-') { $column = $column === NULL ? $this->column : $column; return $this->grid->addFilterDateRange($this->key, $this->name, $column, $name_second); }
/** * Create grid UI component (Ublaboo/DataGrid * * @param array|IRepository|Selection $data * @param string $primaryKey * @param integer $perPage * @param array $permanentlyFilter * @param Nette\ComponentModel\IContainer|null $parent * @param string|null $name * * @return DataGrid * @throws DataGridException */ public function createUblaboo($data = null, $primaryKey = null, $perPage = null, $permanentlyFilter = [], $parent = null, $name = null) { $grid = new DataGrid($parent, $name); // set primary key if ($primaryKey) { $grid->setPrimaryKey($primaryKey); } // set data source if ($data) { if ($data instanceof IRepository) { $dataSource = new Mepatek\Components\Ublaboo\DataSources\RepositorySource($data, $primaryKey); $dataSource->setPermanentlyFilter($permanentlyFilter); } elseif ($data instanceof Selection) { $dataSource = new NetteDatabaseTableDataSource($data, $primaryKey); } else { $dataSource = new ArrayDataSource($data); } $grid->setDataSource($dataSource); } else { $dataSource = new ArrayDataSource([]); $grid->setDataSource($dataSource); } // set properties of grid if ($this->translator) { $grid->setTranslator($this->translator); } //$grid->setEditableColumns(); $grid->setRememberState(true); // set item per page if ($perPage) { $grid->per_page = $perPage; } return $grid; }
/** * Has particular row and action allowed? * @param mixed $key * @return bool */ public function hasAction($key) { $condition = $this->datagrid->getRowCondition('action', $key); return $condition ? $condition($this->item) : TRUE; }
protected function createComponentGrid($name) { $grid = new DataGrid(NULL, $name); $grid->addExportCsv('export', 'export.csv'); return $grid; }