[x] The bug happens consistently across all tested browsers
[x] This bug happens when using yii2-grid without other plugins.
Workaround
Setting 'filter' => '' (empty string) for that data column makes the filter work fine
Reason for the bug and possible solution
kartik\grid\DataColumn in renderFilterCellContent() method starts by calling parent implementation (so Yii2 native DataColumn::renderFilterCellContent()). All parent implementation does is creating basic dropdown/text input filter, which obviously cannot take array data Select2 uses. As parent implementation starts by checking if filter is a string and returns it instead in such scenario - so that kartik implementation can do its own "magic" - it skips the faulty (and unnecessary) native filter creation.
Possibly parent call can be omitted when filterType is specified or 'filter' => '' could be set by default when filterType is specified? Setting it manually for each column (filter) feels hacky.
Prerequisites
master
branch of yii2-grid.Steps to reproduce the issue
GridView
withActiveDataProvider
that has a column with active filterSelect2
filter with some data andmultiple
input allowed:Expected behavior and actual behavior
When I follow those steps, I see
Array to string conversion
error fromyiisoft/yii2/helpers/BaseHtml.php
at line569
is thrown.I was expecting the filter to be rendered properly with values I selected
Environment
Browsers
Operating System
Libraries
3.6.1
3.5.3
Isolating the problem
Workaround
'filter' => ''
(empty string) for that data column makes the filter work fineReason for the bug and possible solution
kartik\grid\DataColumn
inrenderFilterCellContent()
method starts by callingparent
implementation (so Yii2 nativeDataColumn::renderFilterCellContent()
). All parent implementation does is creating basic dropdown/text input filter, which obviously cannot takearray
dataSelect2
uses. As parent implementation starts by checking iffilter
is a string and returns it instead in such scenario - so thatkartik
implementation can do its own "magic" - it skips the faulty (and unnecessary) native filter creation.Possibly parent call can be omitted when
filterType
is specified or'filter' => ''
could be set by default whenfilterType
is specified? Setting it manually for each column (filter) feels hacky.