Update Cgridview From Value Of Dropdown List


I am new to Yii. I have using CGridview in my application. I want the change in the dropdown menu should change cgridview contnents using ajax request. I done following code so far

in view index.php

echo CHtml::dropDownList(‘station_id’, ‘’, $stations,


                    'ajax' => array(






                                    $.fn.yiiGridView.update("playlist-grid", {data: $(this).serialize()});





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


               // 'dataProvider'=>$dataProvider,


















                        'header'=>'Allow Skip',







in controller

public function actionUpdateGrid()


            $sql="SELECT library_media_item.Title,library_media_item.Points,library_media_item.Allow_Skip,

                    artist.Artist_Name FROM library_media_item ,artist WHERE 

                    library_media_item.Artist_ID = artist.Artist_ID";


            $command = $connection->createCommand($sql);

            $songs = $command->queryAll();

            echo $songs;




here cgridview is not updated.

Hi manohar_bomma, welcome to the forum.

Well, the following is not a direct and/or quick answer. But I hope you will find it useful.

Did you play around a bit with a gii-generated admin page? I hope you did. If you didn’t yet, I have to say, you must do it at once.

You will see ‘advanced search form’ in the admin page, and there should be a text field for ‘station_id’. Input some station_id in it and hit ‘search’, then the filtered result will be displayed in the grid using ajax.

So, basically what you have to do is quite simple.

  1. Make ‘advanced search form’ visible from the start.

  2. Delete unnecessary text fields.

  3. Replace ‘station_id’ text field with a drop down list.

  4. Attach an event handler to the selection change event of the drop down list to submit the search form.

And please take a look at this wiki