diff --git a/Datatable/Filter/AbstractFilter.php b/Datatable/Filter/AbstractFilter.php
index 49cc2de6..5623c8cf 100644
--- a/Datatable/Filter/AbstractFilter.php
+++ b/Datatable/Filter/AbstractFilter.php
@@ -11,6 +11,7 @@
namespace Sg\DatatablesBundle\Datatable\Filter;
+use Sg\DatatablesBundle\Datatable\Extension\Select;
use Sg\DatatablesBundle\Datatable\OptionsTrait;
use Symfony\Component\OptionsResolver\OptionsResolver;
@@ -124,7 +125,14 @@ public function configureOptions(OptionsResolver $resolver)
$resolver->setAllowedTypes('search_type', 'string');
$resolver->setAllowedTypes('search_column', array('null', 'string'));
- $resolver->setAllowedTypes('initial_search', array('null', 'string'));
+
+ $allowedInitialSearchTypes = ['null', 'string'];
+ if($this instanceof Select2Filter or $this instanceof Select) {
+ // Add ability to set initial search as array only for Select & Select2 filters
+ $allowedInitialSearchTypes[] = 'array';
+ }
+
+ $resolver->setAllowedTypes('initial_search', $allowedInitialSearchTypes);
$resolver->setAllowedTypes('classes', array('null', 'string'));
$resolver->setAllowedTypes('cancel_button', 'bool');
$resolver->setAllowedTypes('placeholder', 'bool');
@@ -382,7 +390,7 @@ protected function getExpression(Composite $expr, QueryBuilder $qb, $searchType,
case 'bigint':
case 'smallint':
case 'boolean':
- if ($searchValue == (string) (int) $searchValue) {
+ if ( $searchValue == (string) (int) $searchValue ) {
$searchValue = (int) $searchValue;
} else {
$incompatibleTypeOfField = true;
diff --git a/Resources/views/datatable/initial_search.html.twig b/Resources/views/datatable/initial_search.html.twig
index 34daa91a..70691b61 100644
--- a/Resources/views/datatable/initial_search.html.twig
+++ b/Resources/views/datatable/initial_search.html.twig
@@ -5,9 +5,18 @@
#
# For the full copyright and license information, please view the LICENSE
# file that was distributed with this source code.
- #}
+#}
+
"searchCols": [
- {% for column in sg_datatables_view.columnBuilder.columns %}
- {% if column.filter.initialSearch is defined and column.filter.initialSearch|length > 0 %}{"search" : "{{ column.filter.initialSearch }}"}{% else %}null{% endif %},
- {% endfor %}
+{% for column in sg_datatables_view.columnBuilder.columns %}
+ {% if column.filter.initialSearch is defined %}
+ {% if column.filter.initialSearch is iterable %}
+ {"search" : "{% for fi in column.filter.initialSearch %}{{ fi }},{% endfor %}"},
+ {% elseif column.filter.initialSearch|length > 0 %}
+ {"search" : "{{ column.filter.initialSearch }}"},
+ {% else %}
+ null,
+ {% endif %}
+ {% endif %}
+{% endfor %}
]
diff --git a/Resources/views/filter/select.html.twig b/Resources/views/filter/select.html.twig
index 03b34531..f9ade5e9 100644
--- a/Resources/views/filter/select.html.twig
+++ b/Resources/views/filter/select.html.twig
@@ -38,7 +38,15 @@
{% set filter_select_select_options %}
{% for key, name in column.filter.selectOptions %}
- {% if column.filter.initialSearch is not same as(null) and column.filter.initialSearch is same as(key) %}
+ {% if column.filter.initialSearch is iterable %}
+ {% set selected = '' %}
+ {% for fi in column.filter.initialSearch %}
+ {% if fi is not same as(null) and fi is same as(key) %}
+ {% set selected = 'selected="selected"' %}
+ {% endif %}
+ {% endfor %}
+
+ {% elseif column.filter.initialSearch is not same as(null) and column.filter.initialSearch is same as(key) %}
{% else %}