Cgridview data based on dropdownlist value


I have a dropdownlist with an option selected by default. Below the dropdownlist is the grid (Cgridview) which should display only those records satisfying the condition depending on the dropdownlist value.

How do i get the value of dropdownlist in CActiveDataprovider to set the condition?

By default this is set in your gridview as

'dataProvider' => $model->search(),

And you can see the associated code in your controller and model (if gii / giix) generated

If you are overriding your dataprovider just make sure that you invoke a method by which you define your criteria/conditions.

Thanks enfield but ‘dataProvider’ => $model->search() returns only table values. And my dropdownlist vlaues are hardcoded. so i want to know how can i get the selected value of the dropdownlist in the search() function of the model.

I’m a very newbie in Yii framework. I would like to create a page. Which is when the dropdown list change, the listview/gridview will be change by dropdown value. I already stack as tad. I lost 1-2 days on this issue. please help me.

this is my view

<div class="row">


    &#036;records = Company::model()-&gt;findAll();

    &#036;company_list = CHtml::listData(&#036;records, 'id', 'name');

    echo CHtml::dropDownList('company_id','', &#036;company_list,


    'onchange'=&gt;&quot;&#036;.fn.yiiListView.update('ajaxListView', {url: '&quot;.Yii::app()-&gt;createUrl('department/dynamicsectionlist').&quot;?company_id='+&#036;('#company_id option:selected').val()})&quot;,

    'prompt'=&gt;'Please select a company',

    )); ?&gt;



$this->widget(‘zii.widgets.CListView’, array(






This is model

public function search()


    // Warning: Please modify the following code to remove attributes that

    // should not be searched.

    &#036;criteria=new CDbCriteria;







    return new CActiveDataProvider(&#036;this, array(




This is Controller

public function actionDynamicsectionlist()


    &#036;company_id = &#036;_POST['company_id'];

    &#036;criteria=new CDbCriteria();

    &#036;criteria-&gt;condition .= ' IN (SELECT, FROM department t2 WHERE t2.company_id = :company_id)';

    &#036;criteria-&gt;params[':company_id'] = &#036;company_id;

    &#036;dataProvider = new CActiveDataProvider( 'Department', array( 'criteria' =&gt; &#036;criteria, ) );

    &#036;this-&gt;render( 'sectionlist', array( 'dataProvider' =&gt; &#036;dataProvider ) );


But it is not working. Please help me.

Regads Thura747

tad you can send parameter from your dropDownlist in GET via ajax or simple get request, and use it in search.