Skip to content
This repository has been archived by the owner on Feb 4, 2023. It is now read-only.

Add an option 'row_tr_click' for multiselect column #741

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
35 changes: 35 additions & 0 deletions Datatable/Column/MultiselectColumn.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
//-------------------------------------------------
Expand Down Expand Up @@ -164,13 +172,15 @@ 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'));
$resolver->setAllowedTypes('value', 'string');
$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;
}
Expand Down Expand Up @@ -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;
}

}
1 change: 1 addition & 0 deletions Resources/doc/columns.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion Resources/views/datatable/multiselect_actions.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ function updateCheckAll() {
}

{# handle row <tr> 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");
Expand Down
2 changes: 2 additions & 0 deletions Twig/DatatableTwigExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -255,6 +256,7 @@ public function datatablesRenderMultiselectActions(Twig_Environment $twig, Colum
'datatable_name' => $datatableName,
'dom_id' => $domId,
'pipeline' => $pipeline,
'row_tr_click' => $rowTrClick
)
);
}
Expand Down