Skip to content

Commit

Permalink
returned possibility to override row block with own TR tag
Browse files Browse the repository at this point in the history
  • Loading branch information
hrach committed Feb 11, 2017
1 parent d1ea588 commit 6e61244
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 28 deletions.
1 change: 1 addition & 0 deletions doc/default.texy
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ Here is list of suitable blocks for redefinition:
| `global-filter-actions` | cell with the buttons for filtering | `$showCancel`
| `row-actions-edit` | cell for rendering save & cancel buttons while editing row
| `row-actions` | cell for rendering row's actions | `$primary`, `$row`
| `row` | row rendering, for `<tr>` tag decoration | `$rowId`, `$row`
| `col-filter-*` | custom filter cell rendering | `$form` - filter's `Nette\Form\IContainer`, `$column` - Column instance
| `col-filter` | global custom filter cell rendering; this block has lower priority than `col-filter-*` | same variables as for `col-filter-*`
| `col-*` | custom cell rendering; **only this block must include ''<td>'' tags**; | `$row`, `$cell`
Expand Down
8 changes: 7 additions & 1 deletion src/Datagrid.blocks.latte
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,16 @@
<a href="{link edit! $primary}" class="ajax" data-datagrid-edit>{$control->translate(Edit)}</a>
{/define}

{define row-class}
{define row}
<tr id={$rowId}>
{include #row-inner row => $row}
</tr>
{/define}

{define row-inner}
{var $primary = $control->getter($row, $rowPrimaryKey)}
{php if (!$sendOnlyRowParentSnippet): $this->global->snippetDriver->enter("rows-$primary", "dynamic"); endif;}

{var $editRow = $editRowKey == $primary && $primary !== NULL && $editRowKey !== NULL}
{foreach $columns as $column}
{var $cell = $control->getter($row, $column->name, FALSE)}
Expand Down Expand Up @@ -125,6 +130,7 @@
{/if}
</td>
{/if}
{php if (!$sendOnlyRowParentSnippet): $this->global->snippetDriver->leave(); endif;}
{/define}

{define pagination}
Expand Down
52 changes: 28 additions & 24 deletions src/Datagrid.latte
Original file line number Diff line number Diff line change
Expand Up @@ -7,53 +7,57 @@
<div class="grid" data-grid-name="{$control->getUniqueId()}">
{snippet rows}

{var $_templates = []}
{foreach $cellsTemplates as $cellsTemplate}
{import $cellsTemplate}
{php
$_template = $this->createTemplate($cellsTemplate, $this->params, "import");
$_template->render();
$_templates[] = $_template;
}
{/foreach}
{import Datagrid.blocks.latte}

{form form class => 'ajax'}
{var $hasActionsColumn = (bool) $control->getEditFormFactory()}{* we may render only one row so the form[filter] may not be created *}
{ifset row-actions}{var $hasActionsColumn = true}{/ifset}
{ifset global-actions}{var $hasActionsColumn = true}{/ifset}

{php
$hasActionsColumn =
(bool) $control->getEditFormFactory() /* we may render only one row so the form[filter] may not be created */
|| isset($this->blockQueue["row-actions"])
|| isset($this->blockQueue["global-actions"]);
foreach ($_templates as $_template):
$_template->params['hasActionsColumn'] = $hasActionsColumn;
endforeach;
$this->params['hasActionsColumn'] = $hasActionsColumn;
}

{include #table-open-tag}
<thead>
{include #row-head-columns hasActionsColumn => $hasActionsColumn}
{include #row-head-columns}
{ifset $form['filter']}
{include #row-head-filter}
{/ifset}
</thead>
<tbody>
{if count($data)}
{if $sendOnlyRowParentSnippet}
{foreach $data as $row}
{var $primary = $control->getter($row, $rowPrimaryKey)}
<tr id="{$this->global->snippetDriver->getHtmlId("rows-$primary")}" class="{include row-class}">
{include #row-inner row => $row, hasActionsColumn => $hasActionsColumn}
</tr>
{/foreach}
{else}
{foreach $data as $row}
{var $primary = $control->getter($row, $rowPrimaryKey)}
<tr n:snippet="rows-$primary" class="{include row-class}">
{include #row-inner row => $row, hasActionsColumn => $hasActionsColumn}
</tr>
{/foreach}
{/if}
{foreach $data as $row}
{var $primary = $control->getter($row, $rowPrimaryKey)}
{var $rowId = $this->global->snippetDriver->getHtmlId("rows-$primary")}
{include #row row => $row, rowId => $rowId}
{/foreach}
{else}
{ifset #empty-result}{include #empty-result}{/ifset}
{/if}
</tbody>
<tfoot>
{if isset($paginator)}
<tfoot n:ifset="$paginator">
<tr>
<th colspan="{=count($columns) + $hasActionsColumn}">
{include #pagination}
</th>
</tr>
{/if}
</tfoot>
{include #table-close-tag}

{/form}

{/snippet}
</div>
8 changes: 5 additions & 3 deletions src/Datagrid.php
Original file line number Diff line number Diff line change
Expand Up @@ -222,9 +222,11 @@ public function addCellsTemplate($path)
}


public function getCellsTemplate()
public function getCellsTemplates()
{
return $this->cellsTemplates;
$templates = $this->cellsTemplates;
$templates[] = __DIR__ . '/Datagrid.blocks.latte';
return $templates;
}


Expand Down Expand Up @@ -265,7 +267,7 @@ public function render()
$this->template->rowPrimaryKey = $this->rowPrimaryKey;
$this->template->paginator = $this->paginator;
$this->template->sendOnlyRowParentSnippet = $this->sendOnlyRowParentSnippet;
$this->template->cellsTemplates = $this->cellsTemplates;
$this->template->cellsTemplates = $this->getCellsTemplates();
$this->template->showFilterCancel = $this->filterDataSource != $this->filterDefaults; // @ intentionaly
$this->template->setFile(__DIR__ . '/Datagrid.latte');

Expand Down

0 comments on commit 6e61244

Please sign in to comment.