diff --git a/src/DataGrid.php b/src/DataGrid.php index ed173638..8f7ec325 100644 --- a/src/DataGrid.php +++ b/src/DataGrid.php @@ -417,6 +417,11 @@ class DataGrid extends Control */ private $customPaginatorTemplate = null; + /** + * @var string + */ + private $componentFullName; + public function __construct(?IContainer $parent = null, ?string $name = null) { @@ -469,8 +474,9 @@ function (Presenter $presenter): void { $this->gridSession = $sessionSection; } - } - ); + + $this->componentFullName = $this->lookupPath(); + }); } @@ -1549,10 +1555,10 @@ public function filterSucceeded(Form $form): void if ($edit['submit']->isSubmittedBy() && $edit->getErrors() === []) { $this->inlineEdit->onSubmit($id, $values['inline_edit']); $this->getPresenterInstance()->payload->_datagrid_inline_edited = $id; - $this->getPresenterInstance()->payload->_datagrid_name = $this->getName(); + $this->getPresenterInstance()->payload->_datagrid_name = $this->getFullName(); } else { $this->getPresenterInstance()->payload->_datagrid_inline_edit_cancel = $id; - $this->getPresenterInstance()->payload->_datagrid_name = $this->getName(); + $this->getPresenterInstance()->payload->_datagrid_name = $this->getFullName(); } if ($edit['submit']->isSubmittedBy() && $this->inlineEdit->onCustomRedraw !== []) { @@ -2273,7 +2279,7 @@ public function reload(array $snippets = []): void } $this->getPresenterInstance()->payload->_datagrid_url = $this->refreshURL; - $this->getPresenterInstance()->payload->_datagrid_name = $this->getName(); + $this->getPresenterInstance()->payload->_datagrid_name = $this->getFullName(); $this->onRedraw(); } else { @@ -2288,7 +2294,7 @@ public function reloadTheWholeGrid(): void $this->redrawControl('grid'); $this->getPresenterInstance()->payload->_datagrid_url = $this->refreshURL; - $this->getPresenterInstance()->payload->_datagrid_name = $this->getName(); + $this->getPresenterInstance()->payload->_datagrid_name = $this->getFullName(); $this->onRedraw(); } else { @@ -2897,7 +2903,7 @@ public function handleInlineEdit($id): void if ($presenter->isAjax()) { $presenter->payload->_datagrid_inline_editing = true; - $presenter->payload->_datagrid_name = $this->getName(); + $presenter->payload->_datagrid_name = $this->getFullName(); } $this->redrawItem((int) $id, $primaryWhereColumn); @@ -2990,6 +2996,23 @@ public function getColumnsSummary(): ?ColumnsSummary * INTERNAL * ********************************************************************************/ + /** + * Gets component's full name in component tree + * @return string + * @throws DataGridHasToBeAttachedToPresenterComponentException + */ + public function getFullName() : string + { + if ($this->componentFullName === null) { + throw new DataGridHasToBeAttachedToPresenterComponentException( + 'Datagrid needs to be attached to presenter in order to get its full name.' + ); + } + + return $this->componentFullName; + } + + /** * Tell grid filters to by submitted automatically */ diff --git a/src/GroupAction/GroupActionCollection.php b/src/GroupAction/GroupActionCollection.php index b52964e0..aed796fb 100644 --- a/src/GroupAction/GroupActionCollection.php +++ b/src/GroupAction/GroupActionCollection.php @@ -111,14 +111,14 @@ public function addToFormContainer(Container $container): void $groupActionSelect->addCondition(Form::FILLED) ->toggle( - strtolower((string) $this->datagrid->getName()) . 'group_action_submit' + strtolower((string) $this->datagrid->getFullName()) . 'group_action_submit' ); $container->addSubmit('submit', 'ublaboo_datagrid.execute') ->setValidationScope([$container]) ->setAttribute( 'id', - strtolower((string) $this->datagrid->getName()) . 'group_action_submit' + strtolower((string) $this->datagrid->getFullName()) . 'group_action_submit' ); $form->onSubmit[] = [$this, 'submitted']; @@ -146,7 +146,7 @@ public function submitted(Form $form): void */ $http_ids = $form->getHttpData( Form::DATA_LINE | Form::DATA_KEYS, - strtolower((string) $this->datagrid->getName()) . '_group_action_item[]' + strtolower((string) $this->datagrid->getFullName()) . '_group_action_item[]' ); $ids = array_keys($http_ids); diff --git a/src/templates/datagrid.latte b/src/templates/datagrid.latte index b6d80ed5..cccea428 100644 --- a/src/templates/datagrid.latte +++ b/src/templates/datagrid.latte @@ -14,7 +14,7 @@ * @param InlineEdit|null $inlineAdd Inline add data *} -