PDA

View Full Version : Using AutoLoad with function call instead of url



dillu5c5
19 Nov 2014, 6:44 AM
Hi everyone,
I've a doubt regarding autoLoad property of the Panel component. My panel has an ExtJs chart in it. The data required to plot that is inside a function which helps to plot the chart in the panel.

AutoLoad It generally takes the url: 'users.json' / html / jsp page as input but is there a way to call a function for autoLoading and setting autoRefresh for that function to be called?
like this :
myPanel.getUpdater().startAutoRefresh(timer, callMe());

Instead of :
myPanel.getUpdater().startAutoRefresh(timer, '<%=request.getContextPath()%>/com/abc/webRep/web/ViewDashboard/myJsp.jsp');

I've all required data inside that function. And I need to continuously refresh that panel along with the chart. Please help.

joel.watson
20 Nov 2014, 6:33 PM
Hi dillu5c5--

Yes, you should be able to do that. For example, the second argument of startAutoRefresh() is an object which, among other things, you can use to specify a callback method that should be called when the underlying load() method is complete.

Something like:



var callbackFn = function( elLoader, success, response, opts ) {
// do custom stuff here
}
loader.startAutoRefresh( timer, {
callback: callbackFn
})


Hope that helps!

dillu5c5
20 Nov 2014, 10:51 PM
Hi Joel Watson,
Thanks a ton for the reply. It really helps me. But I'm confused with the 'autoLoad' config of the panel. What url must I specify in that? I don't need to hit any url to get the data.
Please help

joel.watson
21 Nov 2014, 6:56 AM
Hi Joel Watson,
Thanks a ton for the reply. It really helps me. But I'm confused with the 'autoLoad' config of the panel. What url must I specify in that? I don't need to hit any url to get the data.
Please help

If you don't need to use an AJAX request in order to get the data, you might be better off using a different approach than the ElementLoader. Maybe a scheduled task (http://docs.sencha.com/extjs/5.0/apidocs/#!/api/Ext.util.TaskManager) would work better for your purposes? Using this you can still specify intervals at which your specific task would run, but not have to deal unnecessarily with remote requests.

Hope that helps!

dillu5c5
23 Nov 2014, 11:24 PM
Hi Joel,
Thanks a lot for your valuable suggestion. I've realised the task manager's importance for my need. I want to know if it is possible to create series of tasks like writing a for loop to create multiple tasks with respective intervals and run them.
My requirement contains 4 charts in the same dashboard and they have individual time intervals to refresh. So I want to create series of tasks for each of them and run them.

Please help.

joel.watson
24 Nov 2014, 12:07 PM
Hi Joel,
Thanks a lot for your valuable suggestion. I've realised the task manager's importance for my need. I want to know if it is possible to create series of tasks like writing a for loop to create multiple tasks with respective intervals and run them.
My requirement contains 4 charts in the same dashboard and they have individual time intervals to refresh. So I want to create series of tasks for each of them and run them.

Please help.

Glad the suggestion was helpful. Regarding your other question, you can create as many tasks as you need. Are you having issues with creating them?

Thanks

dillu5c5
5 Dec 2014, 6:46 AM
Hi Joel,
Thanks a lot for your valuable reply. I was able to create tasks individually without a loop. But my requirement needs to create tasks based on a loop. So in the loop, when I give the task creation logic, the timing was going wrong as JavaScript is Asynchronous.

I hence rolled back to setAutoRefresh using CLOSURES {avoiding JS's async method} to solve my problem of refreshing the widgets.

Now I've a new problem, when I use this setAutoRefresh() without URL and simply with CallBack function, I'm getting this in the firebug
"POST http://localhost:8080/abc/DEF/Home/undefined 404 (Not Found) "

Structure of my logic :
Ext.getCmp('hiddenRefreshPanel'+i).getUpdater().startAutoRefresh(dashboardDetails.refreshTime, {
callback: function(elLoader, success, response, opts ){
refreshReportWidgets(i);
}
});
How to get rid of this? Please help..

Thanks,
Dileep Kumar :)

joel.watson
5 Dec 2014, 7:06 AM
Hi dillu5c5--

Can you post a full test case here, or (ideally) by creating a runnable fiddle (https://fiddle.sencha.com/#home)? Without seeing the context of your code, it's difficult to know what to suggest. If you can provide a test case, I'll be happy to help test it with you.

Thanks!