Yii 1.1: Update Gridview with Dropdown Selection


I recently worked on updating the content of a gridview based on the selection of a dropdown menu. I thought I should share it in the forum...

In the view you have:

  1. the js script for capturing the onchange of the select:
Yii::app()->clientScript->registerScript('sel_status', "
        $('#selStatus').change(function() {
            $.fn.yiiGridView.update('milestone-category-grid', {
                    data: $(this).serialize()
            return false;
  1. the code for the select:
$data = CHtml::listData(Status::model()->findAll('IsProcess=?',array(1)), 'ID', 'Description');
$select = key($data);
echo CHtml::dropDownList(
    $select,            // selected item from the $data
  1. the code for the gridview widget:
    'afterAjaxUpdate' => 'installSortable',
    'enableSorting' => false,
)); ?>
  1. In the "Search" function of your corresponding model the following code needs to capture the GET variable that is being passed, in my case it is 'dropDownStatus', the name given to the select (use Firebug, if necessary, to get the name of the variable being passed):
public function search($status=false)
        // Warning: Please modify the following code to remove attributes that
        // should not be searched.
        $criteria=new CDbCriteria;
        if ($status!==false) {
        if (isset($_GET['dropDownStatus'])) {
            $criteria->order='Position ASC';

With this you have a select and a gridview that updates dynamically, without using ajax.

Feedback welcome...

Total 1 comment

#19859 report it
rlbanuradha at 2016/05/18 04:27pm
$select value not getting passed

I was able to get the selected value in clientscript. but that value not being passed to the search method. Please help.

Leave a comment

Please to leave your comment.

Write new article
  • Written by: lgastmans
  • Category: Tips
  • Yii Version: 1.1
  • Votes: +3 / -1
  • Viewed: 11,085 times
  • Created on: Apr 22, 2014
  • Last updated: never
  • Tags: #gridview, #dropdown