kartik-v / yii2-grid

Enhanced GridView with various utilities for Yii Framework 2.0
http://demos.krajee.com/grid
Other
558 stars 302 forks source link

Multiple-value filter inputs (eg. `Select2`) throw `Array to string conversion` error after filtering #1079

Open BelegUS opened 10 months ago

BelegUS commented 10 months ago

Prerequisites

Steps to reproduce the issue

  1. Create some GridView with ActiveDataProvider that has a column with active filter
  2. Set that column to use Select2 filter with some data and multiple input allowed:
    'filterType' => GridView::FILTER_SELECT2,
    'filterWidgetOptions' => [
    'options' => [
      'multiple' => true,
    ]
    ],
  3. Try filtering with that filter.

Expected behavior and actual behavior

When I follow those steps, I see Array to string conversion error from yiisoft/yii2/helpers/BaseHtml.php at line 569 is thrown.

I was expecting the filter to be rendered properly with values I selected

Environment

Browsers

Operating System

Libraries

Isolating the problem

Workaround

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.