easyfrag
(Easyfrag)
May 8, 2013, 9:55pm
1
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.
perochak
(Amjad Mughal)
May 9, 2013, 6:52am
3
You CGridview settings section do as
'selectionChanged'=>'$.fn.yiiGridView.getSelection(id){
alert(id);
}'
easyfrag
(Easyfrag)
May 9, 2013, 6:32pm
4
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
perochak
(Amjad Mughal)
May 11, 2013, 9:39am
5
If you have the ID of the record, then you can do ajax request to get other data of the that record.
easyfrag
(Easyfrag)
May 19, 2013, 11:17pm
6
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>
perochak
(Amjad Mughal)
May 20, 2013, 10:49am
7
Instead of doing this, do as
function updateonselectionchange(id)
{
var param1 = $.fn.yiiGridView.getSelection(id);
$.ajax({
url:// your URL
data:// data
});
}
easyfrag
(Easyfrag)
May 20, 2013, 8:46pm
8
PeRoChAk:
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