Yii Framework Forum: cGridview TypeError - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

cGridview TypeError Multiple Ajax loaded cGridviews cause TypeError Rate Topic: -----

#1 User is offline   Backslider 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 358
  • Joined: 23-July 09

Posted 09 August 2012 - 03:06 PM

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 ) ) );

We were all once expert at....... nothing.

yii-language-behavior

My Blog
1

#2 User is offline   Backslider 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 358
  • Joined: 23-July 09

Posted 09 August 2012 - 04:57 PM

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';


2. Then in my javascript that handles 'complete' for either of the Ajax requests for the cGridViews I added:

    gridLoaded = 'true';


3. In my Ajax request URLs I added:

    &gridloaded='+gridLoaded;


4. 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!
We were all once expert at....... nothing.

yii-language-behavior

My Blog
1

#3 User is offline   Backslider 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 358
  • Joined: 23-July 09

Posted 09 August 2012 - 05:05 PM

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.
We were all once expert at....... nothing.

yii-language-behavior

My Blog
1

#4 User is offline   Azy 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 154
  • Joined: 16-May 12

Posted 23 September 2013 - 12:02 AM

Thanks a lot for this.

it saved my day!

:)
1

#5 User is offline   bandpay 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 14
  • Joined: 20-June 13
  • Location:Denmark

Posted 06 December 2013 - 07:23 AM

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.

/*
May
The Life
Be Good To You
*******************
*******************
SincerelYii
Babak Bandpey
*/

0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users