0
votes

Is it possible to have a activeDropDownList, which will update the contents of the Gridview widget? I would like not to solve my problem, but only to guide me where to search or how to search. I am using yii2-advanced-app.

1
I guess you want to filter the gridview based on dropdown selection right?SO-user
Base of an id, which will be on the dropdown. Show the appropriate result. Yes, I want to filter the gridview.KostasC
Are you asking for something like this http://i.stack.imgur.com/zA41j.pngSO-user
No, my dropdown, will be outside the gridview widget.KostasC

1 Answers

1
votes

Use javascript to redirect to gridview page with GET value as your dropdown value:

Sample js to redirect:

 $this->registerJs( 
'$(document).ready(function(){ 

$("#sectorid").change(function(){
var e = document.getElementById("sectorid");
    var strSel =  e.options[e.selectedIndex].value;
    window.location.href="'.Yii::$app->urlManager->createUrl('search?sid=').'" + strSel;
});

});', View::POS_READY);

Then in Your Controller pass parameter:

public function actionIndex($id=NULL)
    {
        $searchModel = new ModelSearch();
        $dataProvider = $searchModel->search(Yii::$app->request->queryParams, $id); // passing dropdown parameter
    //Return statements
    }

And in you search model:

public function search($params, $id=NULL)// pass that parameter
    { 
     // query the database with that and return $dataprovider
    }