$.fn.yiiGridView.settings disappear


I have a view that includes 2 gridviews. They work correctly.

Inspecting with Firebug I can see



Then I load a third gridview into a div via ajax. It loads and works ok but…

The settings of the first 2 grids disappear and I am only left with the 3rd grid’s settings.


And I get javascript error "settings is undefined"

Any help please?


It’s difficult to guess whats happening without debugging the code…

Try to pinpoint the exact moment when the first two settings disappears…

They disappear as soon as I write the ajax reply into a div.

Looking at the ajax reply that the controller/action sends back:

<script type="text/javascript" src="/assets/2b060b58/jquery.js"></script>

<script type="text/javascript" src="/assets/2b060b58/jquery.ba-bbq.js"></script>

<script type="text/javascript" src="/assets/a5e685d2/gridview/jquery.yiigridview.js"></script>

So at the controller/action I’ve added

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

And now the three grids have $.fn.yiiGridView.settings :)

I’ve tried excluding the scripts one by one to see which was causing the problem, but it only works when I use the wildcard.



Good catch… the fact is that all these scripts are already included on the page… so on ajax call all three should not be included/added again…

The ajax request will be a fresh page load so as far as yii is concerned the grid javascript hasn’t been loaded.

Had a similar problem with loading dialogs via ajax.

It’s a bit clunky but I just keep an array of loaded assets clientside and send it back with an ajax request to filter out already loaded scripts.

How do you do that alex-w?

Could you show me some code?


I hooked into jQuery’s clean function to catch html being appended.

var _clean      = jQuery.clean;


    clean: function(elems, context, fragment, scripts) {

        var ret = _clean(elems, context, fragment, scripts);

        for (var i in ret) {

            if ((ret[i].tagName || '').match(/(script)/i) && ret[i].src)            

                loadedAssets.push((ret[i].src || '').split('/').pop());




Will catch the script elements and put the filename into the loadedAssets array.

Thankyou very much alex-w!

The simplest way for me to solve this issue was to keep a copy of the settings before loading the grid by ajax in a popup dialog and to restore the old settings after removing the dialog.

var gridSettings = $.fn.yiiGridView.settings;


open: function () {

gridSettings = $.fn.yiiGridView.settings;



close: function () {

$.fn.yiiGridView.settings = gridSettings;