Can't Order Or Filter Cgridview Displayed In Ajax Cjuidialog

Hi.

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


http://localhost/app/mybeautifulapp/myObject/ajaxlist?id_otherobject=10&myObject_sort=name



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)




<?php

	$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>	

<?php

	$this->endWidget();

?>



AjaxList (view from myObject)




<?php

Yii::import('zii.widgets.grid.CGridView');


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

	'id'=>'myObject-grid',

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


	'columns'=>array(

		/*

		array(

			'class'=>'CButtonColumn',

		),

		*/


		array(

				'name'  => 'mainField',

				'type'  => 'raw',

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

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

				

			),

		

		'name',

		'address',


	

		


		

	),

)); ?>	




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.




$this->renderPartial('ajax_view',array(

            'model'=>$model,

            'dataProvider'=>$dataProvider,

            ),false,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.