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

Commit c618016

Browse files
committed
Unique name to allow a datatable multiple times on the same page
1 parent 3c6d6f8 commit c618016

File tree

5 files changed

+28
-5
lines changed

5 files changed

+28
-5
lines changed

Datatable/AbstractDatatable.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,13 @@ abstract class AbstractDatatable implements DatatableInterface
128128
*/
129129
protected $language;
130130

131+
/**
132+
* The unique name for this instance.
133+
*
134+
* @var string
135+
*/
136+
protected $uniqueName;
137+
131138
/**
132139
* The PropertyAccessor.
133140
*
@@ -160,6 +167,7 @@ public function __construct(
160167
Twig_Environment $twig
161168
) {
162169
$this->validateName();
170+
$this->uniqueName = uniqid($this->getName().'-');
163171

164172
$this->authorizationChecker = $authorizationChecker;
165173
$this->securityToken = $securityToken;
@@ -282,6 +290,14 @@ public function getOptionsArrayFromEntities($entities, $keyFrom = 'id', $valueFr
282290
return $options;
283291
}
284292

293+
/**
294+
* {@inheritdoc}
295+
*/
296+
public function getUniqueName()
297+
{
298+
return $this->uniqueName;
299+
}
300+
285301
//-------------------------------------------------
286302
// Private
287303
//-------------------------------------------------

Datatable/DatatableInterface.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,4 +125,11 @@ public function getEntity();
125125
* @return string
126126
*/
127127
public function getName();
128+
129+
/**
130+
* Returns the unique name of this datatable view.
131+
*
132+
* @return string
133+
*/
134+
public function getUniqueName();
128135
}

Resources/views/column/multiselect.html.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@
99
{% extends '@SgDatatables/column/column.html.twig' %}
1010

1111
{% block title %}
12-
"title": "<input type='checkbox' name='sg-datatables-{{ sg_datatables_view.name }}-multiselect-checkall' class='sg-datatables-{{ sg_datatables_view.name }}-multiselect-checkall' />",
12+
"title": "<input type='checkbox' name='sg-datatables-{{ sg_datatables_view.uniqueName }}-multiselect-checkall' class='sg-datatables-{{ sg_datatables_view.uniqueName }}-multiselect-checkall' />",
1313
{% endblock %}

Resources/views/datatable/datatable_html.html.twig

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
{% endif %}
1515
{% endif %}
1616

17-
<table id="sg-datatables-{{ sg_datatables_view.name }}" class="{{ sg_datatables_view.options.classes }}" cellspacing="0" width="100%">
17+
<table id="sg-datatables-{{ sg_datatables_view.uniqueName }}" class="{{ sg_datatables_view.options.classes }}" cellspacing="0" width="100%">
1818
<thead>
1919
{% if true == individual_filtering %}
2020
{% if 'head' == sg_datatables_view.options.individualFilteringPosition or 'both' == sg_datatables_view.options.individualFilteringPosition%}
@@ -23,7 +23,7 @@
2323
<th>{{ column.title }}</th>
2424
{% endfor %}
2525
</tr>
26-
<tr id="sg-datatables-{{ sg_datatables_view.name }}-filterrow">
26+
<tr id="sg-datatables-{{ sg_datatables_view.uniqueName }}-filterrow">
2727
{% for column in sg_datatables_view.columnBuilder.columns %}
2828
<th>
2929
{% if column.searchable %}
@@ -55,5 +55,5 @@
5555
</table>
5656

5757
{% if sg_datatables_view.columnBuilder.uniqueColumn('multiselect') is not same as(null) %}
58-
<div id="sg-datatables-{{ sg_datatables_view.name }}-multiselect-actions"></div>
58+
<div id="sg-datatables-{{ sg_datatables_view.uniqueName }}-multiselect-actions"></div>
5959
{% endif %}

Resources/views/datatable/datatable_js.html.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
1111
$(document).ready(function () {
1212
13-
var selector = "#sg-datatables-{{ sg_datatables_view.name }}";
13+
var selector = "#sg-datatables-{{ sg_datatables_view.uniqueName }}";
1414
var oTable;
1515
1616
var defaults = {

0 commit comments

Comments
 (0)