jQWidgets Forums
jQuery UI Widgets › Forums › Grid › Data Adapter async: false issue
Tagged: dataadapter async databind
This topic contains 4 replies, has 2 voices, and was last updated by Mark 12 years, 4 months ago.
-
Author
-
Hi,
I am getting some strange behaviour when trying to change one of my calls to be synchronous. I have a JSON service that returns a single class object with one of the properties having two classes below. This can be seen via this URL with a good rest client utility (such as the rest client plugin for Firefox).
http://leadmesh.cloudapp.net/Admin.svc/Campaign/31
The code I have in my page is below, and I was expecting to not have to handle any callbacks as the request is not async, and instead inspect the data adapter directly after the dataBind. This is where it gets interesting – records has two objects (which is strange as I would only expect one), and each one looks in the correct schema with all properties blank.
Even more strangely, if I look at recordids – this is also populated with two objects which are the two child objects from the delivery property and are populated.
If i run this async and look at records in the loadcomplete event – all is perfectly structured (1 top level object, with one of the properties having two child objects).
function LoadCampaign(campaignid) { var campaigndetail_source = { datatype: "json", datafields: [ { name: 'AdvertiserID' }, { name: 'AdvertiserName' }, { name: 'CampaignID' }, { name: 'DateEnd', type: 'date' }, { name: 'DateStart', type: 'date' }, { name: 'DedupeFunction' }, { name: 'FilterFunction' }, { name: 'Revenue' }, { name: 'Deliveries' } ], url: 'http://leadmesh.cloudapp.net/Admin.svc/Campaign/' + campaignid, async: false }; var da_campaigndetail = new $.jqx.dataAdapter(campaigndetail_source, { downloadComplete: function (data, status, xhr) { }, loadComplete: function (data) {} }); da_campaigndetail.dataBind(); }
Any help / pointers to what is going on here would be really appreciated.
Thanks
Mark
Hi Mark,
Setting “async” false to the source object means that the ajax function’s async: false will be set, too. Of course, if you would like, you can override the built-in Ajax function call using the jqxDataAdapter’s loadServerData callback. For more information visit: jquery-data-adapter.htm.
Best Regards,
Peter StoevjQWidgets Team
http://www.jqwidgets.comHi Peter,
Thank you for such a quick response. Just checking my understanding of your response – the data adapter passes through the async flag to an $.ajax call and as such I need to have a callback to handle the request regardless of the async: false?
The purpose of my function was to return da_campaigndetail.records so that the calling function could take out the top level data (always expecting only one top level object) for some ui elements, and bind the .Delivery collection to a grid.
I was struggling with scope / closures to return da_campaigndetail.records so I thought this could be a good solution, but it looks like I cannot get away from the callback
If you have any suggestions on how I can return the records from the loadComplete callback function in the above code I would really appreciate the direction.
Thanks
Mark
Hi Mark,
The data Adapter passes the async flag to the built-in $.ajax call, but if you would like you can manually use the jQuery’s Ajax function without using the dataAdapter’s built-in logic. That’s the idea of the ‘loadServerData’ callback. Take a look at the help article as there’s an implementation of the callback there.
Best Regards,
Peter StoevjQWidgets Team
http://www.jqwidgets.comExcellent – will do
Thanks for your help.
Mark
-
AuthorPosts
You must be logged in to reply to this topic.