diff --git a/Datatable/Column/AbstractColumn.php b/Datatable/Column/AbstractColumn.php index 20fc01dd..9820fff3 100644 --- a/Datatable/Column/AbstractColumn.php +++ b/Datatable/Column/AbstractColumn.php @@ -355,6 +355,39 @@ public function configureOptions(OptionsResolver $resolver) return $this; } + public function getOptions(): array + { + $options = [ + 'cellType' => $this->cellType, + 'contentPadding' => $this->contentPadding, + 'defaultContent' => $this->defaultContent, + 'name' => $this->name, + 'width' => $this->width, + 'title' => $this->title, + 'searchable' => $this->searchable, + 'visible' => $this->visible, + 'orderable' => $this->orderable, + 'responsivePriority' => $this->responsivePriority, + 'data' => $this->data, + ]; + + if (true === $this->visible) { + $options['className'] = $this->className; + } + + if (false === $this->visible) { + $options['className'] = 'never '.$this->className; + } + + if (true === $this->orderable) { + $options['orderSequence'] = $this->orderSequence; + $options['orderData'] = $this->orderData; + } + + // ignore null values + return array_filter($options); + } + //------------------------------------------------- // ColumnInterface //------------------------------------------------- @@ -411,14 +444,6 @@ public function isSelectColumn() return true; } - /** - * {@inheritdoc} - */ - public function getOptionsTemplate() - { - return '@SgDatatables/column/column.html.twig'; - } - /** * {@inheritdoc} */ diff --git a/Datatable/Column/ColumnInterface.php b/Datatable/Column/ColumnInterface.php index 05a86c58..9508a3db 100644 --- a/Datatable/Column/ColumnInterface.php +++ b/Datatable/Column/ColumnInterface.php @@ -57,12 +57,7 @@ public function isToManyAssociation(); */ public function isSelectColumn(); - /** - * Get the template, in which all DataTables-Columns-Options set. - * - * @return string - */ - public function getOptionsTemplate(); + public function getOptions(): array; /** * Sometimes it is necessary to add some special data to the output array. diff --git a/Datatable/Column/MultiselectColumn.php b/Datatable/Column/MultiselectColumn.php index b2ebb5eb..a0c07668 100644 --- a/Datatable/Column/MultiselectColumn.php +++ b/Datatable/Column/MultiselectColumn.php @@ -65,12 +65,11 @@ public function isUnique() return true; } - /** - * {@inheritdoc} - */ - public function getOptionsTemplate() + public function getOptions(): array { - return '@SgDatatables/column/multiselect.html.twig'; + return [ + 'title' => "", + ]; } /** diff --git a/Resources/doc/columns.md b/Resources/doc/columns.md index 4bf30478..a366cfdb 100644 --- a/Resources/doc/columns.md +++ b/Resources/doc/columns.md @@ -16,10 +16,6 @@ Represents the most basic column. -### Options template - -@SgDatatables/column/column.html.twig - ### Cell content template @SgDatatables/render/column.html.twig @@ -166,10 +162,6 @@ ___ Represents a column, optimized for boolean values. -### Options template - -@SgDatatables/column/column.html.twig - ### Cell content template @SgDatatables/render/boolean.html.twig @@ -234,10 +226,6 @@ Represents a column, optimized for date time values. **Be sure to install the [Bootstrap Date Range Picker](http://www.daterangepicker.com/) plugin before using the DateRangeFilter.** -### Options template - -@SgDatatables/column/column.html.twig - ### Cell content template @SgDatatables/render/datetime.html.twig @@ -286,10 +274,6 @@ Represents a column, optimized for images. A complete example of an ImageColumn can be found in the [demo bundle](https://github.com/stwe/DtBundleDemo10). -### Options template - -@SgDatatables/column/column.html.twig - ### Cell content template @SgDatatables/render/thumb.html.twig @@ -348,10 +332,6 @@ ___ Represents a virtual column. -### Options template - -@SgDatatables/column/column.html.twig - ### Options All options of [Column](#1-column), except `data`, `join_type` and `editable`. @@ -413,10 +393,6 @@ ___ A Column to display CRUD action labels or buttons. -### Options template - -@SgDatatables/column/column.html.twig - ### Cell content template @SgDatatables/render/action.html.twig @@ -550,10 +526,6 @@ ___ Support for Bulk Actions. -### Options template - -@SgDatatables/column/multiselect.html.twig - ### Cell content template @SgDatatables/render/multiselect.html.twig @@ -671,10 +643,6 @@ Represents a column, optimized for numbers. **The intl extension is needed.** -### Options template - -@SgDatatables/column/column.html.twig - ### Options All options of [Column](#1-column). @@ -723,11 +691,6 @@ ___ Represents a column, with a `span` tag with `data-*` attributes. The displayed data is in the `span` tag. - -### Options template - -@SgDatatables/column/attributeColumn.html.twig - ### Options All options of [Column](#1-column). diff --git a/Resources/views/column/column.html.twig b/Resources/views/column/column.html.twig deleted file mode 100644 index e87f0d35..00000000 --- a/Resources/views/column/column.html.twig +++ /dev/null @@ -1,64 +0,0 @@ -{## - # This file is part of the SgDatatablesBundle package. - # - # (c) stwe - # - # For the full copyright and license information, please view the LICENSE - # file that was distributed with this source code. - #} -{ - {% block common %} - {% if column.cellType is not same as(null) %} - "cellType": "{{ column.cellType }}", - {% endif %} - {% if column.contentPadding is not same as(null) %} - "contentPadding": "{{ column.contentPadding }}", - {% endif %} - {% if column.defaultContent is not same as(null) %} - "defaultContent": {{ column.defaultContent|json_encode|raw }}, - {% endif %} - {% if column.name is not same as(null) %} - "name": "{{ column.name }}", - {% endif %} - {% if column.width is not same as(null) %} - "width": "{{ column.width }}", - {% endif %} - {% block title %} - {% if column.title is not same as(null) %} - "title": {{ column.title|json_encode|raw }}, - {% endif %} - {% endblock %} - {% if column.searchable is same as(true) or column.searchable is same as(false) %} - "searchable": {{ column.searchable|sg_datatables_bool_var }}, - {% endif %} - {% if column.visible is same as(true) %} - "visible": true, - {% if column.className is not same as(null) %} - "className": "{{ column.className }}", - {% endif %} - {% endif %} - {% if column.visible is same as(false) %} - "visible": false, - "className": "never {% if column.className is not same as(null) %}{{ column.className }}{% endif %}", - {% endif %} - {% if column.orderable is same as(true) %} - "orderable": true, - {% if column.orderSequence is not same as(null) %} - "orderSequence": {{ column.orderSequence|raw }}, - {% endif %} - {% if column.orderData is not same as(null) %} - "orderData": {{ column.orderData }}, - {% endif %} - {% endif %} - {% if column.orderable is same as(false) %} - "orderable": false, - {% endif %} - {% if column.responsivePriority is not same as(null) %} - "responsivePriority": {{ column.responsivePriority }}, - {% endif %} - {% endblock %} - - {% block data %} - "data": "{{ column.data }}", - {% endblock %} -}, diff --git a/Resources/views/column/multiselect.html.twig b/Resources/views/column/multiselect.html.twig deleted file mode 100644 index 98c2df85..00000000 --- a/Resources/views/column/multiselect.html.twig +++ /dev/null @@ -1,13 +0,0 @@ -{## - # This file is part of the SgDatatablesBundle package. - # - # (c) stwe - # - # For the full copyright and license information, please view the LICENSE - # file that was distributed with this source code. - #} -{% extends '@SgDatatables/column/column.html.twig' %} - -{% block title %} - "title": "", -{% endblock %} diff --git a/Resources/views/datatable/columns.html.twig b/Resources/views/datatable/columns.html.twig index ac3eeaf0..e5b9c38b 100644 --- a/Resources/views/datatable/columns.html.twig +++ b/Resources/views/datatable/columns.html.twig @@ -9,7 +9,7 @@ "columns": [ {% for column in sg_datatables_view.columnBuilder.columns %} {% if column.sentInResponse %} - {% include column.getOptionsTemplate %} + {{ column.getOptions()|json_encode|raw }}, {% endif %} {% endfor %} ]