Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions src/Datagrid.blocks.latte
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,10 @@
{input button}
{/define}

{define row-actions-delete-link}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Document.

<a href="{link delete! $primary}" class="ajax" data-datagrid-delete>{$control->translate(Delete)}</a>
{/define}

{define row-insert}
{formContainer insert-data}
{foreach $columns as $column}
Expand Down Expand Up @@ -179,8 +183,13 @@
{else}
{ifset #row-actions}
{include #row-actions row => $row, primary => $primary}
{elseif $control->getEditFormFactory()}
{include #row-actions-edit-link row => $row, primary => $primary}
{else}
{if $control->getEditFormFactory()}
{include #row-actions-edit-link row => $row, primary => $primary}
{/if}
{if $control->getDeleteCallback()}
{include #row-actions-delete-link row => $row, primary => $primary}
{/if}
{/ifset}
{/if}
</td>
Expand Down
3 changes: 2 additions & 1 deletion src/Datagrid.latte
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
(bool) $control->getEditFormFactory() /* we may render only one row so the form[filter] may not be created */
|| isset($this->blockQueue["row-actions"])
|| isset($form["insert"])
|| isset($form["filter"]);
|| isset($form["filter"])
|| $control->getDeleteCallback();
$hasGlobalActionsColumn = isset($form['actions']);

foreach ($_templates as $_template):
Expand Down
24 changes: 24 additions & 0 deletions src/Datagrid.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ class Datagrid extends UI\Control
/** @var callable|null */
protected $editFormCallback;

/** @var callable|null */
protected $deleteCallback;

/** @var callable|null */
protected $filterFormFactory;

Expand Down Expand Up @@ -257,6 +260,18 @@ public function getFilterFormFactory()
}


public function setDeleteCallback(callable $callback = null)
{
$this->deleteCallback = $callback;
}


public function getDeleteCallback()
{
return $this->deleteCallback;
}


public function addGlobalAction($name, $label, callable $action)
{
$this->globalActions[$name] = [$label, $action];
Expand Down Expand Up @@ -489,6 +504,15 @@ public function handleEdit($primaryValue, $cancelEditPrimaryValue = null)
}


public function handleDelete($primaryValue)
{
call_user_func($this->deleteCallback, $primaryValue);
if ($this->presenter->isAjax()) {
$this->redrawControl('rows');
}
}


public function handleSort()
{
if ($this->presenter->isAjax()) {
Expand Down