/** * @param \Grido\Grid $grid * @param string $name * @param string $label */ public function __construct($grid, $name, $label) { $name = Helpers::formatColumnName($name); $this->addComponentToGrid($grid, $name); $this->label = $label; $this->type = get_class($this); $form = $this->getForm(); $filters = $form->getComponent(self::ID, FALSE); if ($filters === NULL) { $filters = $form->addContainer(self::ID); } $filters->addComponent($this->getFormControl(), $name); }
/** * @param \Nette\Forms\Container $container * @throws Exception * @internal */ public function addCheckers(\Nette\Forms\Container $container) { $items = $this->grid->getData(); $primaryKey = $this->getPrimaryKey(); foreach ($items as $item) { try { $primaryValue = $this->grid->getProperty($item, $primaryKey); if (!isset($container[$primaryValue])) { $container->addCheckbox(Helpers::formatColumnName($primaryValue))->controlPrototype->title = $primaryValue; } } catch (\Exception $e) { throw new Exception('You should define some else primary key via $grid->setPrimaryKey() ' . "because currently defined '{$primaryKey}' key is not suitable for operation feature."); } } }
/** * @param mixed $row * @throws Exception * @return mixed */ protected function getValue($row) { $column = $this->getColumn(); if (is_string($column)) { return $this->grid->getProperty($row, Helpers::unformatColumnName($column)); } elseif (is_callable($column)) { return callback($column)->invokeArgs(array($row)); } else { throw new Exception('Column must be string or callback.'); } }
/** * Returns filter component. * @param string $name * @param bool $need * @return Filter */ public function getFilter($name, $need = TRUE) { return $this->hasFilters() ? $this->getComponent(Filter::ID)->getComponent(Helpers::formatColumnName($name), $need) : NULL; }
/** * @param \Nette\Forms\Container $container * @internal */ public function addCheckers(\Nette\Forms\Container $container) { $items = $this->grid->getData(); $primaryKey = $this->getPrimaryKey(); $propertyAccessor = $this->grid->getPropertyAccessor(); foreach ($items as $item) { $primaryValue = $propertyAccessor->getProperty($item, $primaryKey); if (!isset($container[$primaryValue])) { $container->addCheckbox(Helpers::formatColumnName($primaryValue)); } } }
function _lb7d8b4559e9_table($_b, $_args) { foreach ($_args as $__k => $__v) { ${$__k} = $__v; } echo $control->getTablePrototype()->startTag(); ?> <thead> <tr class="head"> <?php if ($operation) { ?> <th class="checker"<?php if ($filters) { ?> rowspan="<?php if ($filterRenderType == \Grido\Components\Filters\Filter::RENDER_OUTER) { ?> 1<?php } else { ?> 2<?php } ?> "<?php } ?> > <input type="checkbox" title="<?php echo Latte\Runtime\Filters::escapeHtml($template->translate('Grido.Invert'), ENT_COMPAT); ?> "> </th> <?php } $iterations = 0; foreach ($columns as $column) { ?> <?php echo $column->getHeaderPrototype()->startTag(); ?> <?php if ($column->isSortable()) { if (!$column->getSort()) { ?> <a class="ajax" href="<?php echo Latte\Runtime\Filters::escapeHtml($_control->link("sort!", array(array($column->getName() => \Grido\Components\Columns\Column::ORDER_ASC))), ENT_COMPAT); ?> "><?php echo $column->getLabel(); ?> </a> <?php } if ($column->getSort() == \Grido\Components\Columns\Column::ORDER_ASC) { ?> <a class="sort ajax" href="<?php echo Latte\Runtime\Filters::escapeHtml($_control->link("sort!", array(array($column->getName() => \Grido\Components\Columns\Column::ORDER_DESC))), ENT_COMPAT); ?> "><?php echo $column->getLabel(); ?> </a> <?php } if ($column->getSort() == \Grido\Components\Columns\Column::ORDER_DESC) { ?> <a class="sort ajax" href="<?php echo Latte\Runtime\Filters::escapeHtml($_control->link("sort!", array(array($column->getName() => \Grido\Components\Columns\Column::ORDER_ASC))), ENT_COMPAT); ?> "><?php echo $column->getLabel(); ?> </a> <?php } ?> <span></span> <?php } else { ?> <?php echo $column->getLabel(); ?> <?php } ?> <?php echo $column->getHeaderPrototype()->endTag(); ?> <?php $iterations++; } if ($showActionsColumn) { ?> <th class="actions center"> <?php echo Latte\Runtime\Filters::escapeHtml($template->translate('Grido.Actions'), ENT_NOQUOTES); ?> </th> <?php } ?> </tr> <?php if ($filterRenderType == \Grido\Components\Filters\Filter::RENDER_INNER && $filters) { ?> <tr class="filter inner"> <?php $iterations = 0; foreach ($columns as $column) { if ($column->hasFilter()) { ?> <?php echo $control->getFilter($column->getName())->getWrapperPrototype()->startTag(); ?> <?php $_formStack[] = $_form; $formContainer = $_form = $_form["filters"]; ?> <?php $_input = is_object($column->getName()) ? $column->getName() : $_form[$column->getName()]; echo $_input->getControl(); ?> <?php $_form = array_pop($_formStack); ?> <?php echo $control->getFilter($column->getName())->getWrapperPrototype()->endTag(); ?> <?php } elseif ($column->headerPrototype->rowspan != 2) { ?> <th> </th> <?php } $iterations++; } ?> <?php call_user_func(reset($_b->blocks['action']), $_b, get_defined_vars()); ?> </tr> <?php } ?> </thead> <tfoot> <tr> <td colspan="<?php echo Latte\Runtime\Filters::escapeHtml($showActionsColumn ? $columnCount + 1 : $columnCount, ENT_COMPAT); ?> "> <?php call_user_func(reset($_b->blocks['operations']), $_b, get_defined_vars()); call_user_func(reset($_b->blocks['paginator']), $_b, get_defined_vars()); call_user_func(reset($_b->blocks['count']), $_b, get_defined_vars()); ?> </td> </tr> </tfoot> <tbody> <?php $propertyAccessor = $control->getPropertyAccessor(); $iterations = 0; foreach ($data as $row) { $checkbox = $operation ? $form[\Grido\Components\Operation::ID][\Grido\Helpers::formatColumnName($propertyAccessor->getProperty($row, $control->getComponent(\Grido\Components\Operation::ID)->getPrimaryKey()))] : NULL; $tr = $control->getRowPrototype($row); $tr->class[] = $checkbox && $checkbox->getValue() ? 'selected' : NULL; ?> <?php echo $tr->startTag(); ?> <?php if ($checkbox) { ?> <td class="checker"> <?php echo Latte\Runtime\Filters::escapeHtml($checkbox->getControl(), ENT_NOQUOTES); ?> </td> <?php } $iterations = 0; foreach ($columns as $column) { $td = $column->getCellPrototype($row); ?> <?php echo $td->startTag(); ?> <?php if (is_string($column->getCustomRender()) && $column->getCustomRenderVariables()) { $_b->templates['7742270037']->renderChildTemplate($column->getCustomRender(), array_merge(array('control' => $control, 'presenter' => $control->getPresenter(), 'item' => $row, 'column' => $column), $column->getCustomRenderVariables(), array()) + $template->getParameters()); } elseif (is_string($column->getCustomRender())) { $_b->templates['7742270037']->renderChildTemplate($column->getCustomRender(), array('control' => $control, 'presenter' => $control->getPresenter(), 'item' => $row, 'column' => $column) + $template->getParameters()); } else { ?> <?php echo $column->render($row); ?> <?php } ?> <?php echo $td->endTag(); ?> <?php $iterations++; } if ($showActionsColumn) { ?> <td class="actions center"> <?php $iterations = 0; foreach ($actions as $action) { if (is_object($action)) { $_l->tmp = $action; } else { $_l->tmp = $_control->getComponent($action); } if ($_l->tmp instanceof Nette\Application\UI\IRenderable) { $_l->tmp->redrawControl(NULL, FALSE); } $_l->tmp->render($row); $iterations++; } if (!$actions) { ?> <?php } ?> </td> <?php } ?> <?php echo $tr->endTag(); ?> <?php $iterations++; } if (!$control->getCount()) { ?> <tr><td colspan="<?php echo Latte\Runtime\Filters::escapeHtml($showActionsColumn ? $columnCount + 1 : $columnCount, ENT_COMPAT); ?> " class="no-results"><?php echo Latte\Runtime\Filters::escapeHtml($template->translate('Grido.NoResults'), ENT_NOQUOTES); ?> </td></tr> <?php } ?> </tbody> <?php echo $control->getTablePrototype()->endTag(); ?> <?php }