Yii Framework Forum: How to add Jui Autocomplete in Yii2 GridView filter column - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

How to add Jui Autocomplete in Yii2 GridView filter column GridView filter Jui autocomplete Rate Topic: -----

#1 User is offline   Dhrubajyoti Das 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 2
  • Joined: 14-March 17

Posted 10 January 2018 - 11:36 PM

Hello all.

I am a beginner in Yii2 and trying to add jquery ui autocomplete widget in Yii2 GridView filter column, with this code in the grid view filter column...

'filter' => AutoComplete::widget([
'model' => $searchModel,
'attribute' => 'site_id',
'clientOptions' => [
    'minLength' => 3,
    'autoFill' => true,
    'source' => new JsExpression('
        function(request, response) {
            jQuery.getJSON("'.Url::to(['site/search']).'",
            {query: request.term}, function(data) {
                var suggestions = [];
                jQuery.each(data, function(index, ele) {
                    suggestions.push({
                        label: ele.name,
                        value: ele.id
                    });
                });
                response(suggestions);
            });
        }'),
    'select' => new JsExpression('
        function(event, ui) {
            jQuery("#'.Html::getInputId($searchModel, 'site_id').'")
                .val("ui.item.value");
            jQuery("#'.Html::.'").yiiGridView("applyFilter");
        }')
],
]),


This code works to filter GridView data by 'site_id' column.

Current GridView look like this photo:
Attached File  photo-1.png (30.17K)
Number of downloads: 2

What I want to show like this photo:
Attached File  photo-2.png (25.5K)
Number of downloads: 2

I want to show the 'name' field to the user in the jui autocomplete input element, and store the 'site_id' value in a hidden html input element to send with the GridView filter query. How to do this?

Update:

I added '. Html::hiddenInput('name', 'value')' and configured. It's working fine. Thank you all.
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users