Yii Framework Forum: Yii Cgridview Selectionchanged - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Yii Cgridview Selectionchanged yii CGridView selectionChanged Rate Topic: -----

#1 User is offline   easyfrag 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 6
  • Joined: 08-May 13

Posted 08 May 2013 - 04:55 PM

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
0

#2 User is offline   Fabrizio Caldarelli 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 285
  • Joined: 21-March 13
  • Location:Rome, Italy

Posted 08 May 2013 - 05:07 PM

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

#3 User is offline   PeRoChAk 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 578
  • Joined: 26-November 10
  • Location:Lahore, Pakistan

Posted 09 May 2013 - 01:52 AM

You CGridview settings section do as

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

Cheers
Perochak
Web Design - Logo Design - Application Development

My Blog | Forums Comparison
0

#4 User is offline   easyfrag 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 6
  • Joined: 08-May 13

Posted 09 May 2013 - 01:32 PM

View PostPeRoChAk, 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
0

#5 User is offline   PeRoChAk 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 578
  • Joined: 26-November 10
  • Location:Lahore, Pakistan

Posted 11 May 2013 - 04:39 AM

If you have the ID of the record, then you can do ajax request to get other data of the that record.
Cheers
Perochak
Web Design - Logo Design - Application Development

My Blog | Forums Comparison
1

#6 User is offline   easyfrag 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 6
  • Joined: 08-May 13

Posted 19 May 2013 - 06:17 PM

View PostPeRoChAk, 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>
0

#7 User is offline   PeRoChAk 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 578
  • Joined: 26-November 10
  • Location:Lahore, Pakistan

Posted 20 May 2013 - 05:49 AM

Instead of doing this, do as
function updateonselectionchange(id)
{
var param1 = $.fn.yiiGridView.getSelection(id);
$.ajax({
url:// your URL
data:// data
});

}

Cheers
Perochak
Web Design - Logo Design - Application Development

My Blog | Forums Comparison
1

#8 User is offline   easyfrag 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 6
  • Joined: 08-May 13

Posted 20 May 2013 - 03:46 PM

View PostPeRoChAk, on 20 May 2013 - 05:49 AM, said:

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 :)
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users