buttle
(Christopher Fanning)
January 19, 2011, 1:52pm
1
Hi,
I have a view that includes 2 gridviews. They work correctly.
Inspecting with Firebug I can see
$.fn.yiiGridView.settings["waiting-grid"]
$.fn.yiiGridView.settings["active-grid"]
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.
$.fn.yiiGridView.settings["completed-grid"]
And I get javascript error "settings is undefined"
Any help please?
Chris.
mdomba
(Maurizio Domba Cerin)
January 19, 2011, 1:58pm
2
It’s difficult to guess whats happening without debugging the code…
Try to pinpoint the exact moment when the first two settings disappears…
buttle
(Christopher Fanning)
January 19, 2011, 2:31pm
3
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.
Thanks,
Chris.
mdomba
(Maurizio Domba Cerin)
January 19, 2011, 2:35pm
4
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…
alex-w
(Pr0j3ct A1ex)
January 19, 2011, 3:23pm
5
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.
buttle
(Christopher Fanning)
January 20, 2011, 7:51am
6
How do you do that alex-w?
Could you show me some code?
Thanks.
alex-w
(Pr0j3ct A1ex)
January 20, 2011, 9:05am
7
I hooked into jQuery’s clean function to catch html being appended.
var _clean = jQuery.clean;
jQuery.extend({
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.
buttle
(Christopher Fanning)
January 21, 2011, 4:59pm
8
alex-w:
I hooked into jQuery’s clean function to catch html being appended.
var _clean = jQuery.clean;
jQuery.extend({
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!
doomhz
(Dumitru Gl)
August 26, 2011, 1:55pm
9
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;
$(’’).dialog({
open: function () {
gridSettings = $.fn.yiiGridView.settings;
$(’#container ’).load(’/the-new-grid’);
},
close: function () {
$.fn.yiiGridView.settings = gridSettings;
});