Small fix: in refreshGoogleTable, this_request needs to be updated needs to be defined just after the call to send() so that is incremented by 1:
... } this_request = this.last_request[id].id; // <-- HERE! this.gqueries[id].send( function(response) { ... Jose. On Jun 3, 2:01 pm, Jose Luis Canciani <jose.canci...@gmail.com> wrote: > Ok, I've found a way to ignore cancel requests from the client. I'm > posting it here in case someone finds it useful. I still would love > someone explaining my previous questions, but at least I'm able to > continue the development. > > The general idea is to use a datasource id in the browser, and store a > request id that will increment each time a new Query.send() is done > (or if the user hits the "cancel" buttom). So here it is (please > excuse any syntax/error, this is just an extract of my code with the > lines that explains what I did): > > // prototype class for storing google query objects > var GQuery = Class.create({ > initialize: function(){ > this.gtables = []; > this.gqueries = []; > this.last_request = []; > }, > createGoogleTable: function(datasourceID,parent_div) { > // create the Google Visualization Table > this.gtables[datasourceID] = new google.visualization.Table($ > (parent_div)); > // create the google Query object > this.gqueries[datasourceID] = new google.visualization.Query( > 'YOUR_URL_HERE?p_datasource_id='+datasourceID > ); > // create an entry to track it's calls (so we can cancel > future > calls) > this.last_request[datasourceID] = { > "id": 0, > "waiting": false > } > // run the query! > this.refreshGoogleTable(datasourceID); > }, > refreshGoogleTable: function(id) { > var this_request = this.last_request[id].id; > // check for currently running request for the same datasource > if (this.last_request[id].waiting) { > // found one running > alert( 'We are processing a previous request. '+ > 'Please wait or cancel it before trying > again.')); > return false; > } else { > // set the new run session! > this.last_request[id].id += 1; > this.last_request[id].waiting = true; > } > this.gqueries[id].send( function(response) { > if (this_request < query.last_request[id].id) { > // old datasource was canceled, do nothing. > return false; > } > if (response.isError()) { > alert('Error found: ' + > response.getMessage()); > } else { > // redraw the table > > query.gtables[id].draw(response.getDataTable()); > // clean loading flag > query.last_request[id].waiting = false; > }; > }); > }, > cancelGoogleTable: function(id) { > // set a new request id so that the handler ignores the > previous one > run.last_request[id].id += 1; > run.last_request[id].waiting = false; > }}); > > // instantiate and use it! > query = new GQuery; > query.create('datasourceid','parent_div_id'); > // then just call refresh or cancel methods as you wish in your page > > Regards, > Jose. > > On Jun 3, 12:14 pm, Jose Luis Canciani <jose.canci...@gmail.com> > wrote: > > > I'm still trying to make this work. I've ignored the first option > > because I've read in the forums that we should not modify the tqx > > parameters. > > So I'm concentrating in the second option but still having problems. I > > can manually change the query by modifying the Da attribute > > (query_object.Da), but it doesn't help since I cannot receive a custom > > parameter in the response. The response object ignores any custom > > parameters sent in the JSON from the server. > > > So still trying to control this. I've been testing a bit more with two > > different handlers in each call to send(). But I find out that if I > > sent two queries (query.send()) one after the other, then only the > > first one call the response handler. The second one does nothing (I do > > see the two request did get out of the client with Firebug). Can > > someone explain why this happen? > > > Thanks, > > Jose. > > > On Jun 2, 6:37 pm, Jose Luis Canciani <jose.canci...@gmail.com> wrote: > > > > Hello. I'm building a UI that will let a user run a query dynamically > > > and also cancel it if it's taking to long or if he/she wants to run it > > > again with a different filter for example. I'm having troubles to > > > ignore the previous call from the client. I see two possible solutions > > > but I'm not sure how to implement them: > > > > 1) If I could make reqId to increase with every new call to the send() > > > method of the Query object then I could ignore previous calls in my > > > handler function. But I don't know how to do that: when calling the > > > send method the reqId always stay in "0". > > > > 2) I can create a new query object and pass a custom reqId in the URL. > > > That would make the trick, but I don't want to have to create a new > > > object every time. Is it possible to change the URL of a query object > > > once it was instantiated? > > > > Any other approach would be appreciated. > > > > Thanks! > > > Jose. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Google Visualization API" group. To post to this group, send email to google-visualization-api@googlegroups.com To unsubscribe from this group, send email to google-visualization-api+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/google-visualization-api?hl=en -~----------~----~----~----~------~----~------~--~---