Yii1 CHtml::dropDownList: how to convert to Yii2 ?

My Yii1 site uses the following dropdownList above a gridview to select one filter.

After choosing a filter the gridview is updated to show only the matching records.


echo CHtml::dropDownList('filter', $filter, $model->getFilterMenuArray('Contacts'),

    array(

        'submit'=> array('contact/admin'),

        'params'=> array('filter'=> 'js: $(this).val()'),

        'csrf'=> true,

    )

); ?>

How can I update this to Yii2?

I´m a little bit confused, because I found Html::dropDownList, ButtonDropdown::widget, Nav::widget etc.

But they don´t seem to have a submit parameter?!

I tried to change it using onchange with $.ajax.

After changing the dropdownlist the GET is fired, I can see the get-call in Yiis debugger.

The Controller "actionIndex" in ContactController is called, so I can read out the &filter parameter.

[b]My only problem is: The grid is not refreshed, the old records are still there.

I need to refresh the grid. How?[/b]

Loading the page via browser URL is working without problems: index.php?r=contact&filter=K




  public function actionIndex()

    {


        $filter= isset($_GET['filter']) ? $_GET['filter'] : '';


        if ($filter=='') {

            $dataProvider = new ActiveDataProvider([

                'query' => Contact::find()

            ]);

        }

        else {

            $dataProvider = new ActiveDataProvider([

                'query' => Contact::find()->where(['art'=> $filter])

            ]);

        }


        return $this->render('index', [

             'dataProvider' => $dataProvider,

        ]);

    }




echo Html::dropDownList(

       'testlist', //name

       'L',        //preselect

       ['L'=>'L', 'K'=>'K'],   //items


       [ 'onchange'=>"$.ajax({

    type  : 'GET',

    cache : false,

    url  : 'index.php?r=contact',

    data : {filter: this.value},

    error: function() { alert('ajax failed')},

    success : function(response) {

        console.log('onchange ok');

    }

    }); return true;" ]


);

Yii2-grid uses PJAX to refresh. See this article for some examples.

http://www.ramirezcobos.com/2014/04/26/how-to-use-gridview-with-ajax-on-yii2/