EasyUI Forum

General Category => EasyUI for jQuery => Topic started by: devnull on February 25, 2013, 02:20:23 AM



Title: prevent loadData unless specifically called
Post by: devnull on February 25, 2013, 02:20:23 AM
I believe that by default, when the page containing an easyui element is loaded into the browser, all of the elements will automatically make ajax calls to retrieve their data.

I have an application which instead of loading new html pages upon a menu click, it hides, shows a div on one single .html page to reveal the selected contents, but this means that when my page is loaded (refreshed) into the browser, every element will be make ajax calls which is not very efficient and not really what I want to do, as there are potentially a LOT of elements.

So is it possible to GLOBALLY prevent ALL elements from loading their data unless the loadData or reload command is specifically called ??

Right now, I have added a new attribute urx="somepage.php" to each input and then i copy the urx value to the element's url variable when the panel is selected and the parent div's style is changed from hidden to display, bu this is not very efficient.

Many Thanks






Title: Re: prevent loadData unless specifically called
Post by: stworthy on February 25, 2013, 06:25:37 AM
Many components have 'onBeforeLoad' event, which can be used to determine if to load data. Here is the code shows how to prevent from loading data into datagrid at first time and call 'reload' method again to load data normally.
Code:
$('#dg').datagrid({
    onBefore:function(){
var opts = $(this).datagrid('options');
if (!opts.canLoad){
opts.canLoad = true;
return false;
}
    }
});

The loading behavior can also be applied to all the datagrid components.
Code:
$.fn.datagrid.defaults.onBeforeLoad = function(){
var opts = $(this).datagrid('options');
if (!opts.canLoad){
opts.canLoad = true;
return false;
}
}