I have a custom XMLHttpRequest link on each row of my grid. When my users click on it I'd like to display the same progress indicator (the spinning arrows) that shows for sorting and filtering while waiting for the response. Can anyone tell me how to display it when my request starts and then hide it when the response comes back?
Apparently I can...it just took little digging. For anyone looking to do something similar, here is what I did.
In the javascript of my page, I declared two page level variables (outside of any javascript function) like so:
var thegrid = null;var theprogressindicator = null;
I then added a couple of client side functions, one to initialize the variables and another to set the progress indicator state (note that the name of the initializelayouthandler is defined using the grid.displaylayout.clientsideevents object in my server-side code):
function grid_InitializeLayoutHandler(gridName){ thegrid = igtbl_getGridById(gridName); theprogressindicator = thegrid.getProgressIndicator(); theprogressindicator.setLocation(33); // above the grid, centered}
function Progress(state){ if(state == 'on') { theprogressindicator.display(); } else // state == 'off' { theprogressindicator.hide(); }}
Then all I needed to do was to call the Progress() function from inside my XMLHttpRequest functions, turning the indicator on when the request is sent, and then turning it off when response readyState is "complete":
function SendRequest(thesource, theuser, theimage){ //do some stuff . . ohttp = getXMLHTTPObject(); ohttp.onreadystatechange = displayStatus; ohttp.open('GET', theurl, true); ohttp.send(); //--- TURN ON SPINNING ARROWS HERE Progress('on'); return;}
function displayStatus(){ if(ohttp.readyState == 4) // request is complete { //--- TURN OFF SPINNING ARROWS HERE Progress('off'); if (ohttp.status == 200) //--- success { // --- Do more stuff } }}
And that's pretty much all there was to it. The progress indicator now shows up when the users click on the action icon of any given row and displays until the xmlhttp request completes. Sweet!