Multiple Cgridviews & Dynamic Loading

Hi,

I’ve been stumped by a CGridView problem all day and hoping someone can help (please?!).

I have a single page web that loads all content dynamically via AJAX/renderPartial calls. The page loads two CGridView components, each with their own data provider, and rendered in their own view. They both display content correctly, but when a CGridView pagnation button is clicked at the bottom (i.e. 1,2,3, etc), I get a JS error from the jquery.yiigridview.js file (line 252):


Uncaught TypeError: Cannot read property 'ajaxType' of undefined 

This is the function in the JS file that has the error (last line):


update: function (options) {

	var customError;

	if (options && options.error !== undefined) {

		customError = options.error;

		delete options.error;

	}


	return this.each(function () {

		var $form,

			$grid = $(this),

			id = $grid.attr('id'),

			settings = gridSettings[id];


		options = $.extend({

			type: settings.ajaxType,

Looking at the file via the debugger, the settings variable is empty, and the gridSettings array only ever contains one set of CGridView settings (it should have two). The other CGridView component on the page works fine with pagnation, as it is loaded last. If I swap the order of how they are dynamically loaded, the broken CGridView works and the working CGridView breaks.

My CGridView components are standard:

view #1:




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

	'id'=>'notes-grid',

	'dataProvider'=>$dataProvider,

));

view #2:




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

	'id'=>'alerts-grid',

	'dataProvider'=>$dataProvider,

));[



This is the function I use to load the views:


function addAjaxPanel(YiiURL, panelID) {

	$.ajax({

		type: "POST",

		url:    YiiURL,


		success: function(data){

			panelID = '#' + panelID;

			$(panelID).empty().append(data);

		},

		error: function(xhr){

			console.log("Failed to load AJAX panel: "+xhr.readyState+this.url)

		}

	});

}

What looks to be happening is only the last CGridView component’s settings are being saved by the jquery.yiigridview.js file. Has anyone come across this problem before, and any tips on how to conquer it? Any input is appreciated, thank you!

I managed to figure it out - I needed to stop the yiigridview.js script from being included twice by both views:

main.php config file:


'clientScript' => array(

	// disable yiigridview auto include

	'scriptMap'=>array(

        	'jquery.yiigridview.js'=>false)),

Then I copied the jquery.yiigridview.js to my javascript directory and referenced it in the main layout so it gets called only once. All is peachy now!