From a42ae9b2755f0801a09896d7cea5fd99fa7fdefd Mon Sep 17 00:00:00 2001 From: Matthieu BARBE Date: Sat, 17 Feb 2018 12:03:30 +0100 Subject: [PATCH] Add an option 'row_tr_click' for multiselect column --- Datatable/Column/MultiselectColumn.php | 35 +++++++++++++++++++ Resources/doc/columns.md | 1 + .../datatable/multiselect_actions.html.twig | 2 +- Twig/DatatableTwigExtension.php | 2 ++ 4 files changed, 39 insertions(+), 1 deletion(-) diff --git a/Datatable/Column/MultiselectColumn.php b/Datatable/Column/MultiselectColumn.php index 7331eb89..4685d7dd 100644 --- a/Datatable/Column/MultiselectColumn.php +++ b/Datatable/Column/MultiselectColumn.php @@ -61,6 +61,14 @@ class MultiselectColumn extends ActionColumn */ protected $renderActionsToId; + /** + * Click on the entire line for the checkbox otherwise only on the first column. + * Default: true + * + * @var bool + */ + protected $rowTrClick; + //------------------------------------------------- // ColumnInterface //------------------------------------------------- @@ -164,6 +172,7 @@ public function configureOptions(OptionsResolver $resolver) 'value_prefix' => false, 'render_actions_to_id' => null, 'render_if' => null, + 'row_tr_click' => true, )); $resolver->setAllowedTypes('attributes', array('null', 'array')); @@ -171,6 +180,7 @@ public function configureOptions(OptionsResolver $resolver) $resolver->setAllowedTypes('value_prefix', 'bool'); $resolver->setAllowedTypes('render_actions_to_id', array('null', 'string')); $resolver->setAllowedTypes('render_if', array('null', 'Closure')); + $resolver->setAllowedTypes('row_tr_click', 'bool'); return $this; } @@ -323,4 +333,29 @@ public function setRenderActionsToId($renderActionsToId) return $this; } + + /** + * Get row tr click. + * + * @return bool + */ + public function isRowTrClick() + { + return $this->rowTrClick; + } + + /** + * Set row tr click. + * + * @param bool $rowTrClick + * + * @return $this + */ + public function setRowTrClick($rowTrClick) + { + $this->rowTrClick = $rowTrClick; + + return $this; + } + } diff --git a/Resources/doc/columns.md b/Resources/doc/columns.md index 10578300..fa99f998 100644 --- a/Resources/doc/columns.md +++ b/Resources/doc/columns.md @@ -566,6 +566,7 @@ All options of [Action Column](#4-action-column), except `title`. | value_prefix | bool | false | | Use the Datatable-Name as prefix for the value. | | render_actions_to_id | null or string | null | | Id selector where all multiselect actions are rendered. | | render_if | null or Closure | null | | Render a Checkbox only if conditions are TRUE. | +| row_tr_click | bool | true | | Click on the entire line to select the checkbox if the value is true. If the value is false, the chechbox is selected only on the first column. | ### Example diff --git a/Resources/views/datatable/multiselect_actions.html.twig b/Resources/views/datatable/multiselect_actions.html.twig index dab2ef53..a6e0c21e 100644 --- a/Resources/views/datatable/multiselect_actions.html.twig +++ b/Resources/views/datatable/multiselect_actions.html.twig @@ -104,7 +104,7 @@ function updateCheckAll() { } {# handle row click #} -$("#sg-datatables-{{ datatable_name }} tbody").on("click", "tr", function () { +$("#sg-datatables-{{ datatable_name }} tbody").on("click", "tr {% if row_tr_click == false %}> td:first {% endif %}", function () { {# add 'selected' class #} if ($(this).find("input").length) { $(this).toggleClass("selected"); diff --git a/Twig/DatatableTwigExtension.php b/Twig/DatatableTwigExtension.php index 65696374..72bf4708 100644 --- a/Twig/DatatableTwigExtension.php +++ b/Twig/DatatableTwigExtension.php @@ -215,6 +215,7 @@ public function datatablesRenderMultiselectActions(Twig_Environment $twig, Colum $actions = $this->accessor->getValue($multiselectColumn, 'actions'); $domId = $this->accessor->getValue($multiselectColumn, 'renderActionsToId'); $datatableName = $this->accessor->getValue($multiselectColumn, 'datatableName'); + $rowTrClick = $this->accessor->getValue($multiselectColumn, 'rowTrClick'); /** @var Action $action */ foreach ($actions as $actionKey => $action) { @@ -255,6 +256,7 @@ public function datatablesRenderMultiselectActions(Twig_Environment $twig, Colum 'datatable_name' => $datatableName, 'dom_id' => $domId, 'pipeline' => $pipeline, + 'row_tr_click' => $rowTrClick ) ); }