Yii Cgridview Selectionchanged

Hi

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.

thanks

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

You CGridview settings section do as




'selectionChanged'=>'$.fn.yiiGridView.getSelection(id){

alert(id);

}'



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.????

<script>

function updateonselectionchange(id)

{

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

<?php

echo CHtml::ajax(


    array('url'=&gt;CController::createUrl('site/ajaxrequest'),


        'type'=&gt;'POST',


        'data'=&gt;array('params1'=&gt;'1234567'),


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


            {


               alert(data);                 


            }&quot;,


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


    )


);

?>

}

</script>

Instead of doing this, do as




function updateonselectionchange(id)

{

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

$.ajax({

url:// your URL

data:// data

});


}



Cheers that worked for me :)