PDA

View Full Version : Intoducing delay when store is loading



webfriend13
7 May 2012, 10:48 PM
Hi All,

I have two button (1. LoadStore 2. ReadStore). First buttons loads the store while Second button read from the store & applies some filter on in. User first clicks on LoadStore button and then he presses ReadStore button. When user clicks on ReadStore button, I want the function to wait until store is fully loaded. How can I acheive this. Obviously I can initially disable ReadStore buton and enable it after store is loaded but i dont want to take that way. The idea is simple, if the store is not loaded & user have clicked on ReadStore button wait till the time store is loaded. Please provide your suggestion.

Thanks in advance

vietits
7 May 2012, 10:55 PM
You should wait for the 'load' event on LoadStore.

webfriend13
7 May 2012, 11:28 PM
Hi Vietits,

Thank you quick reply. What do you meant by wait for 'load' event. Can you please provide some code snippet.

vietits
8 May 2012, 12:00 AM
1. Solution using callback function


function onLoadStore(){
// code to disable ReadStore button here
LoadStore.load({
callback: function(){
// code to enable ReadStore button and other actions
}
})
}

2. Solution using 'load' event


// listen to load event to LoadStore. This is set one time only.
LoadStore.on('load', function(){
// code to enable ReadStore button and other actions
});
...
function onLoadStore(){
// code to disable ReadStore button
LoadStore.load();
}

webfriend13
8 May 2012, 12:11 AM
Hi Vietits,

Thank you for quick code snippets. I really appreciate your help. I dont want to use approach which involves enabling and disabling the button (application users does not like such implementation). While I am thankful to you for providing quick response, both the solution you have provided is doing the same thing but in different way.


Thank you again for response. Can you please suggest any other alternatives.

vietits
8 May 2012, 12:22 AM
Then you can check loading property of LoadStore each time user click ReadStore button


function onReadStoreButtonClick(){
if(! LoadStore.loading){
// do what you want here
}
}

debabrata
8 May 2012, 6:18 AM
You can set a flag in the LoadStore handler function to check LoadStore button was pressed or not. In Readstore button handler you can check if that flag was not set then load the store and in callback function you can do your requirement.