From a1629cd57681f7556228ff1e657b88d8e9e56b11 Mon Sep 17 00:00:00 2001 From: Dalibor Korpar Date: Thu, 12 May 2016 12:20:17 +0200 Subject: [PATCH] Hide group action checkboxes and selectbox if group action is not allowed on any row --- src/DataGrid.php | 11 +++++++++++ src/templates/datagrid.latte | 12 ++++++------ 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/src/DataGrid.php b/src/DataGrid.php index 8c27ebbb..5787cc80 100644 --- a/src/DataGrid.php +++ b/src/DataGrid.php @@ -384,15 +384,24 @@ public function render() } $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()); } } + if($hasGroupActionOnRows){ + $hasGroupActionOnRows = $this->hasGroupActions(); + } + if ($this->isTreeView()) { $this->getTemplate()->add('tree_view_has_children_column', $this->tree_view_has_children_column); } @@ -413,6 +422,8 @@ public function render() $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) */ diff --git a/src/templates/datagrid.latte b/src/templates/datagrid.latte index 5db3fd6a..c27cb289 100644 --- a/src/templates/datagrid.latte +++ b/src/templates/datagrid.latte @@ -48,9 +48,9 @@ {/if} - + - {foreach $columns as $key => $column} @@ -197,7 +197,7 @@ {? $inlineEdit->onSetDefaults($filter['inline_edit'], $item); } - + {foreach $columns as $key => $column} {var $col = 'col-' . $key} @@ -220,7 +220,7 @@ {else} - - + {foreach $columns as $key => $column} {var $col = 'col-' . $key}
- {if $control->hasGroupActions()} + {if $hasGroupActionOnRows} {block group_actions} {_'ublaboo_datagrid.group_actions'}: {foreach $filter['group_action']->getControls() as $form_control} @@ -111,7 +111,7 @@
+
+ {if $row->hasGroupAction()} getName()|noescape} name="group_action_item[{$row->getId()}]"> {/if} @@ -373,7 +373,7 @@ {? $inlineAdd->onSetDefaults($filter['inline_add']); }