From a6f04bcc4d1685b77ece4c090750eb4b360ca80c Mon Sep 17 00:00:00 2001 From: Philippe MILINK Date: Mon, 20 Aug 2018 23:23:06 +0200 Subject: [PATCH] Add colReorder extension --- Datatable/Extensions.php | 34 +++++++++++++++++++ Resources/doc/extensions.md | 27 +++++++++++++++ .../views/datatable/extensions.html.twig | 5 +++ 3 files changed, 66 insertions(+) diff --git a/Datatable/Extensions.php b/Datatable/Extensions.php index 87d2bf6f..7caca52c 100644 --- a/Datatable/Extensions.php +++ b/Datatable/Extensions.php @@ -69,6 +69,15 @@ class Extensions */ protected $rowGroup; + /** + * The ColReorder Extension. + * Reorder columns + * Default: null + * + * @var null|bool + */ + protected $colReorder; + //------------------------------------------------- // Ctor. //------------------------------------------------- @@ -99,12 +108,14 @@ public function configureOptions(OptionsResolver $resolver) 'responsive' => null, 'select' => null, 'row_group' => null, + 'col_reorder' => null, )); $resolver->setAllowedTypes('buttons', array('null', 'array', 'bool')); $resolver->setAllowedTypes('responsive', array('null', 'array', 'bool')); $resolver->setAllowedTypes('select', array('null', 'array', 'bool')); $resolver->setAllowedTypes('row_group', array('null', 'array', 'bool')); + $resolver->setAllowedTypes('col_reorder', array('null', 'bool')); return $this; } @@ -228,4 +239,27 @@ public function setRowGroup($rowGroup) return $this; } + + /** + * Get colReorder. + * + * @return null|bool + */ + public function getColReorder() + { + return $this->colReorder; + } + + /** + * Set colReorder. + * + * @param null|bool + * @return $this + */ + public function setColReorder($colReorder) + { + $this->colReorder = $colReorder; + + return $this; + } } diff --git a/Resources/doc/extensions.md b/Resources/doc/extensions.md index eadb003f..c0afe7ee 100644 --- a/Resources/doc/extensions.md +++ b/Resources/doc/extensions.md @@ -4,6 +4,7 @@ 2. [Responsive](#2-responsive) 3. [Select](#3-select) 4. [RowGroup](#4-rowgroup) +5. [ColReorder](#4-colreorder) ## 1. Buttons @@ -360,3 +361,29 @@ With the RowGroup class you can set the following options, for details see the [ | endRender | array or null | null | Provide a function that can be used to control the data shown in the end grouping row. | | startRender | array or null | null | Provide a function that can be used to control the data shown in the start grouping row. | ___ + + +## 5. ColReorder + +**Be sure to install the [ColReorder Extension](https://datatables.net/extensions/colreorder/) before using.** + +### Template + +@SgDatatables/datatable/extensions.html.twig + +### Initialisation + +Just add `col_reorder` to your extensions options with the value `true`: + +``` php +public function buildDatatable(array $options = array()) +{ + // ... + + $this->extensions->set(array( + 'col_reorder' => true, + )); + + // ... +} +``` \ No newline at end of file diff --git a/Resources/views/datatable/extensions.html.twig b/Resources/views/datatable/extensions.html.twig index 66dcba4e..9af9e2c3 100644 --- a/Resources/views/datatable/extensions.html.twig +++ b/Resources/views/datatable/extensions.html.twig @@ -135,4 +135,9 @@ startClassName: '{{ sg_datatables_view.extensions.rowGroup.startClassName }}' {% endif %} }, +{% endif %} + +{# ColReorder Extension #} +{% if sg_datatables_view.extensions.colReorder is same as(true) %} + colReorder: true, {% endif %} \ No newline at end of file