diff --git a/contributte-datagrid/app/Presenters/ActionsPresenter.php b/contributte-datagrid/app/Presenters/ActionsPresenter.php index c5e978b2..851d2b1b 100755 --- a/contributte-datagrid/app/Presenters/ActionsPresenter.php +++ b/contributte-datagrid/app/Presenters/ActionsPresenter.php @@ -9,7 +9,7 @@ use Ublaboo\DataGrid\Column\Action\Confirmation\StringConfirmation; use Ublaboo\DataGrid\DataGrid; -final class ActionsPresenter extends Presenter +class ActionsPresenter extends Presenter { /** diff --git a/contributte-datagrid/app/Presenters/GroupActionsPresenter.php b/contributte-datagrid/app/Presenters/GroupActionsPresenter.php index 06ce13b1..d9bb1b06 100755 --- a/contributte-datagrid/app/Presenters/GroupActionsPresenter.php +++ b/contributte-datagrid/app/Presenters/GroupActionsPresenter.php @@ -8,7 +8,7 @@ use Nette\Application\UI\Presenter; use Ublaboo\DataGrid\DataGrid; -final class GroupActionsPresenter extends Presenter +class GroupActionsPresenter extends Presenter { /** diff --git a/contributte-datagrid/app/Presenters/RowPresenter.php b/contributte-datagrid/app/Presenters/RowPresenter.php new file mode 100755 index 00000000..cb5aa888 --- /dev/null +++ b/contributte-datagrid/app/Presenters/RowPresenter.php @@ -0,0 +1,95 @@ +setDataSource($this->dibiConnection->select('*')->from('users')); + + $grid->setItemsPerPageList([20, 50, 1]); + + $grid->setRowCallback(function($item, $tr) { + $tr->addClass('super-' . $item->id); + }); + + $grid->addColumnNumber('id', 'Id') + ->setAlign('left') + ->setSortable(); + + $grid->addColumnText('name', 'Name') + ->setSortable(); + + $grid->addColumnDateTime('birth_date', 'Birthday'); + + $grid->addAction('detail', '', 'this') + ->setIcon('sun') + ->setTitle('Detail'); + + $grid->addAction('delete', '', 'delete!') + ->setIcon('trash') + ->setTitle('Delete') + ->setClass('btn btn-xs btn-danger ajax') + ->setConfirmation( + new StringConfirmation('Do you really want to delete example %s?', 'name') + ); + + $grid->addGroupAction('Delete')->onSelect[] = [$this, 'groupDelete']; + + $grid->allowRowsGroupAction(function($item): bool { + return $item->id % 2 === 0; + }); + + $grid->allowRowsAction('delete', function($item) { + return $item->id % 3 === 0; + }); + + $grid->allowRowsAction('detail', function($item) { + return $item->id % 4 === 0; + }); + + return $grid; + } + + + public function handleDelete(): void + { + $this->flashMessage('Deleted!', 'info'); + $this->redrawControl('flashes'); + } + + + public function groupDelete(array $ids): void + { + $this->flashMessage( + sprintf('These items: [%s] are being deleted', implode($ids, ',')), + 'info' + ); + + if ($this->isAjax()) { + $this->redrawControl('flashes'); + $this['grid']->redrawControl(); + } else { + $this->redirect('this'); + } + } +} + diff --git a/contributte-datagrid/app/templates/@layout.latte b/contributte-datagrid/app/templates/@layout.latte index dc7c58bf..08a44e35 100755 --- a/contributte-datagrid/app/templates/@layout.latte +++ b/contributte-datagrid/app/templates/@layout.latte @@ -42,7 +42,8 @@ 'Columns', 'Filters', 'Actions', - 'Group Actions' + 'Group Actions', + 'Row', ]} {foreach $sections as $section} diff --git a/contributte-datagrid/app/templates/Row/default.latte b/contributte-datagrid/app/templates/Row/default.latte new file mode 100755 index 00000000..ec3ba3a7 --- /dev/null +++ b/contributte-datagrid/app/templates/Row/default.latte @@ -0,0 +1,3 @@ +{block content} + {control grid} +{/block}