Can't Order Or Filter Cgridview Displayed In Ajax Cjuidialog


I managed to let an user open an Ajax modal box to select a foreign key value, displaying the complete CGridView.

The CGridView is inside a view from the object being selected.

Unfortunately, when i click a field title (for example name) to order the records, the page changes to


This is my code:

Button to display the Ajax dialog (inside a view)

	<?php echo CHtml::link('Open list', Yii::app()->createUrl('myobject/AjaxList'),

		array('class' => 'openDlg divDialog', 'onClick'=> "UNINTERESTING_FUNCTION()")); ?>

CJuiDialog (inside the same view)


	$this->beginWidget('zii.widgets.jui.CJuiDialog', array('id'=>'divDialog',

		'options'=>array( 'title'=>'My List', 'autoOpen'=>false, 'modal'=>true, 'width'=>600)));


	<div class="divForForm" id="myResults"></div>	




AjaxList (view from myObject)



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


	'dataProvider'=>$dataProvider, // obviously this comes from the controller








				'name'  => 'mainField',

				'type'  => 'raw',

				'value' => 'CHtml::link($data->mainField, "JAVASCRIPT_FUNCTION_TO_SELECT_FIELD")',

				'htmlOptions' => array('class'=>'chooseField',),










)); ?>	

You need to create your own "click" functions, using the src attributes:

     jQuery("#myLink").on("click", function() {

         var URL = jQuery(this).attr("src");

         jQuery.ajax({'url': URL .........

         return false;


I finally found the solution, i hope it will help anyone with the same problem.

When you call renderPartial you must set the 3rd parameter = FALSE and the 4th parameter = TRUE.





From the official documentation:

$return | boolean | whether the rendering result should be returned instead of being displayed to end users

$processOutput | boolean | whether the rendering result should be postprocessed using processOutput.

And the MOST IMPORTANT TWEAK: Inside the view rendered with renderPartial you must add:

Yii::app()->clientscript->scriptMap['jquery.js'] = false;

The page was reloaded simply 'cause jquery was loaded multiple times.