getId() public method

Get id value of item
public getId ( ) : mixed
return mixed
Beispiel #1
0
 /**
  * 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;
 }
Beispiel #2
0
 /**
  * Get th/td column element
  * @param  string   $tag th|td
  * @param  string   $key
  * @param  Row|NULL $row
  * @return Html
  */
 public function getElementPrototype($tag, $key = NULL, Row $row = NULL)
 {
     /**
      * Get cached element
      */
     if (empty($this->el_cache[$tag])) {
         $this->el_cache[$tag] = $el = $el = Html::el($tag);
     } else {
         $el = $this->el_cache[$tag];
     }
     /**
      * If class was set by user via $el->class = '', fix it
      */
     if (!empty($el->class) && is_string($el->class)) {
         $class = $el->class;
         unset($el->class);
         $el->class[] = $class;
     }
     $el->class[] = "text-{$this->getAlign()}";
     /**
      * Method called from datagrid template, set appropriate classes and another attributes
      */
     if ($key !== NULL && $row !== NULL) {
         $el->class[] = "col-{$key}";
         if ($tag == 'td') {
             if ($this->isEditable()) {
                 $link = $this->grid->link('edit!', ['key' => $key, 'id' => $row->getId()]);
                 $el->data('datagrid-editable-url', $link);
                 $el->data('datagrid-editable-type', $this->editable_element[0]);
                 $el->data('datagrid-editable-attrs', json_encode($this->editable_element[1]));
             }
         }
     }
     return $el;
 }
Beispiel #3
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();
 }