Yii2 grid filter using autocomplete text box

Before using comboBox instead of default (textBox) to search in gridview using this:

[
    'attribute' => 'project_status', 
    'filter' => $someArray,
    'value' => 'projectstatus.name',
]

But I want to switch from comboBox to autocomplete textBox so that the search function still works.

+4
source share
1 answer

In fact, you can set the AutoComplete widget as a filter. The following code works for me:

[
    'attribute' => 'project_status',
    'filter' => AutoComplete::widget([
        'model' => $filterModel,
        'attribute' => 'project_status',
        'clientOptions' => [
            'source' => ['USA', 'RUS'],
        ],
    ]),
    'value' => 'projectstatus.name'
]

Although you may need to slightly modify it to search correctly when choosing a value.

+5
source

All Articles