Yii Cgridview Selectionchanged


I have a zii CGridView displaying dynamic rows from a database table.

When the user selects a new row how do I update some Labels on the Page with fields from the row selected.

I probably need to use a combination of ‘selectionChanged’, $.fn.yiiGridView.getSelection(id) and Javascript but I’m not sure how as I’m new to this.

Any ideas, examples.


Yes, you have to use selectionChanged event to call javascript code.

You CGridview settings section do as




thanks for your reply … that gives me the id of the record… but what is the code to return a field other than the id at client side. ie lets say I want fields 3 and 4

If you have the ID of the record, then you can do ajax request to get other data of the that record.

Ok I’m slowly getting there…On the grids ‘selectionChanged’ I call the function below.

I’m not sure how to pass the id into the ajax data section. How do I replace ‘1234567’ with param1.????


function updateonselectionchange(id)


var param1 = $.fn.yiiGridView.getSelection(id);


echo CHtml::ajax(




        'success' =&gt; &quot;js:function(data)




        'error' =&gt; &quot;function(data, status){ alert(status); }&quot;,                      






Instead of doing this, do as

function updateonselectionchange(id)


var param1 = $.fn.yiiGridView.getSelection(id);


url:// your URL

data:// data



Cheers that worked for me :)