From b8dbf132f5c3859c6cc0218de3b39402674ecb3a Mon Sep 17 00:00:00 2001 From: Philippe MILINK Date: Thu, 28 Jun 2018 18:38:25 +0200 Subject: [PATCH] Add colReorder option --- Datatable/Options.php | 39 +++++++++++++++++++++ Resources/doc/options.md | 1 + Resources/views/datatable/options.html.twig | 3 ++ 3 files changed, 43 insertions(+) diff --git a/Datatable/Options.php b/Datatable/Options.php index 3c0c9162..3c9ecb69 100644 --- a/Datatable/Options.php +++ b/Datatable/Options.php @@ -32,6 +32,15 @@ class Options // These 'null' initialized options uses the default value of the DataTables plugin. //-------------------------------------------------------------------------------------------------- + /** + * Give the possibility to change the order of the columns + * DataTables default: false + * Default: null + * + * @var null|bool + */ + protected $colReorder; + /** * Delay the loading of server-side data until second draw. * DataTables default: null @@ -268,6 +277,7 @@ public function __construct() public function configureOptions(OptionsResolver $resolver) { $resolver->setDefaults(array( + 'col_reorder' => null, 'defer_loading' => null, 'display_start' => null, 'dom' => null, @@ -293,6 +303,7 @@ public function configureOptions(OptionsResolver $resolver) 'global_search_type' => 'like', )); + $resolver->setAllowedTypes('col_reorder', array('null', 'bool')); $resolver->setAllowedTypes('defer_loading', array('null', 'int', 'array')); $resolver->setAllowedTypes('display_start', array('null', 'int')); $resolver->setAllowedTypes('dom', array('null', 'string')); @@ -327,6 +338,34 @@ public function configureOptions(OptionsResolver $resolver) // Getters && Setters //------------------------------------------------- + /** + * Get colReorder. + * + * @return null|bool + */ + public function isColReorder() + { + if (is_array($this->colReorder)) { + return $this->optionToJson($this->colReorder); + } + + return $this->colReorder; + } + + /** + * Set colReorder. + * + * @param null|bool $colReorder + * + * @return $this + */ + public function setColReorder($colReorder) + { + $this->colReorder = $colReorder; + + return $this; + } + /** * Get deferLoading. * diff --git a/Resources/doc/options.md b/Resources/doc/options.md index 8ff25e49..1f40cae0 100644 --- a/Resources/doc/options.md +++ b/Resources/doc/options.md @@ -4,6 +4,7 @@ With 'null' initialized options uses the default value of the DataTables plugin. | Option | Type | Default | Description | |-------------------------------|--------------------|-----------|-------------| +| col_reorder | null or bool | null | Allow the reordering of columns. | | defer_loading | null, int or array | null | Delay the loading of server-side data until second draw. | | display_start | null or int | null | Initial paging start point. | | dom | null or string | null | Define the table control elements to appear on the page and in what order. | diff --git a/Resources/views/datatable/options.html.twig b/Resources/views/datatable/options.html.twig index 87e102d2..aa679583 100644 --- a/Resources/views/datatable/options.html.twig +++ b/Resources/views/datatable/options.html.twig @@ -6,6 +6,9 @@ # For the full copyright and license information, please view the LICENSE # file that was distributed with this source code. #} +{% if sg_datatables_view.options.colReorder is not same as(null) %} + "colReorder": {{ sg_datatables_view.options.colReorder|sg_datatables_bool_var }}, +{% endif %} {% if sg_datatables_view.options.deferLoading is not same as(null) %} "deferLoading": {{ sg_datatables_view.options.deferLoading }}, {% endif %}