From 6e612445484c1ea6616c2d76e2470b595e41d60a Mon Sep 17 00:00:00 2001 From: Jan Skrasek Date: Sat, 11 Feb 2017 15:11:08 +0100 Subject: [PATCH] returned possibility to override row block with own TR tag --- doc/default.texy | 1 + src/Datagrid.blocks.latte | 8 +++++- src/Datagrid.latte | 52 +++++++++++++++++++++------------------ src/Datagrid.php | 8 +++--- 4 files changed, 41 insertions(+), 28 deletions(-) diff --git a/doc/default.texy b/doc/default.texy index 3415e6d..3cdbe66 100644 --- a/doc/default.texy +++ b/doc/default.texy @@ -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 `` 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 '''' tags**; | `$row`, `$cell` diff --git a/src/Datagrid.blocks.latte b/src/Datagrid.blocks.latte index 75468f1..8abc3f8 100644 --- a/src/Datagrid.blocks.latte +++ b/src/Datagrid.blocks.latte @@ -78,11 +78,16 @@ {$control->translate(Edit)} {/define} -{define row-class} +{define row} + + {include #row-inner row => $row} + {/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)} @@ -125,6 +130,7 @@ {/if} {/if} + {php if (!$sendOnlyRowParentSnippet): $this->global->snippetDriver->leave(); endif;} {/define} {define pagination} diff --git a/src/Datagrid.latte b/src/Datagrid.latte index 9d88278..4fc26bf 100644 --- a/src/Datagrid.latte +++ b/src/Datagrid.latte @@ -7,53 +7,57 @@
{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} - {include #row-head-columns hasActionsColumn => $hasActionsColumn} + {include #row-head-columns} {ifset $form['filter']} {include #row-head-filter} {/ifset} {if count($data)} - {if $sendOnlyRowParentSnippet} - {foreach $data as $row} - {var $primary = $control->getter($row, $rowPrimaryKey)} - - {include #row-inner row => $row, hasActionsColumn => $hasActionsColumn} - - {/foreach} - {else} - {foreach $data as $row} - {var $primary = $control->getter($row, $rowPrimaryKey)} - - {include #row-inner row => $row, hasActionsColumn => $hasActionsColumn} - - {/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} - - {if isset($paginator)} + {include #pagination} - {/if} {include #table-close-tag} + {/form} + {/snippet}
diff --git a/src/Datagrid.php b/src/Datagrid.php index ee6f305..67644ee 100644 --- a/src/Datagrid.php +++ b/src/Datagrid.php @@ -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; } @@ -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');