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
Page 1 of 1
Yii Cgridview Selectionchanged yii CGridView selectionChanged
#2
Posted 08 May 2013 - 05:07 PM
Yes, you have to use selectionChanged event to call javascript code.
Yii2 by example: my book about Yii2
https://www.packtpub...nt/yii2-example
https://www.packtpub...nt/yii2-example
#4
Posted 09 May 2013 - 01:32 PM
PeRoChAk, on 09 May 2013 - 01:52 AM, said:
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
#6
Posted 19 May 2013 - 06:17 PM
PeRoChAk, on 11 May 2013 - 04:39 AM, said:
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'=>CController::createUrl('site/ajaxrequest'),
'type'=>'POST',
'data'=>array('params1'=>'1234567'),
'success' => "js:function(data)
{
alert(data);
}",
'error' => "function(data, status){ alert(status); }",
)
);
?>
}
</script>
Share this topic:
Page 1 of 1