cGridview TypeError

I have two cGridview widgets that are Ajax loaded into separate DOM elements using renderPartial. Each cGridview and their pagers have unique IDs.

Both views that contain the CGridviews have the following, since jQuery is already loaded:




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

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



Upon loading the first view, everything functions as normal and I can page and filter the cGridView without a problem.

If I load the second cGridview, it also functions normally.

The problem: After loading the second cGridview, the first ceases to function and throws the following error in Firebug when paged or filtered:




TypeError: settings is undefined

[Break On This Error] 	


return fn.apply( context, args.concat( slice.call( arguments ) ) );



This is how I solved the problem, which is caused by the second request reloading the javascript files, thus overwriting the first.

  1. I created a global javascript variable in my main view in which the grids are rendered:



    var gridLoaded = 'false';



  1. Then in my javascript that handles ‘complete’ for either of the Ajax requests for the cGridViews I added:



    gridLoaded = 'true';



  1. In my Ajax request URLs I added:



    &gridloaded='+gridLoaded;



  1. Then in both of my view files (since its up to the user as to which is loaded first) I added:



	if($_GET['gridloaded'] == 'true') {

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

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

	}



Works like a charm!

Not tested, but assuming that I register the script files for cGridview in my main view into which the grids are loaded, I could just add the following in my views for the grids:




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

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

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

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



Note that my renderPartial calls have the fourth parameter set to ‘true’, otherwise the grids will not work at all.

Since I already have a lot of stuff loading in my main view, I felt it better to have the cGridview js load with the first grid.

Thanks a lot for this.

it saved my day!

:)

Hi there, :)

I had the exact same problem today.

But it was caused by wrong element ID.

If this happens, give your element a unique custom ID and untilize the new ID if needed and I’m sure that your problem will be solved.

Have a nice day.