CGridView ajax

I’ve included this code in my view page the entire row of the table clickable:


			$(document).ready(function() {

				$(\'.mgrid_click tr\').click(

					function() {

						var href = $(this).find("a").attr("href");

						if(href) {

							window.location = href;






It works fine at first, but after I click the header to sort or go to other page using pagination, the function is not triggered anymore.

Any ideas why? Any ideas how to fix this?


Try with this method :

	<?php $this->widget('zii.widgets.grid.CGridView', array(


		'selectionChanged'=>'function(id){ /* document.location.href = "..." You can use this property : $.fn.yiiGridView.getSelection(id) */ }',


	)); ?>

Thanks for pointing that out,mahdi.

I noticed that when I do this:

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

it returns an ID alternately. Apparently, it only returns the value of the selected row, because clicking the row again deselects it thus returning blank id. But I think I can use this to my benefit :)

That’s exactly as it says in the documentation… $.fn.yiiGridView.getSelection(id) returns the key values of the selected rows…