jQWidgets Forums
jQuery UI Widgets › Forums › DataTable › DataAdapter cacheing data?
This topic contains 5 replies, has 2 voices, and was last updated by James Lavery 10 years, 1 month ago.
-
Author
-
I’ve got a DataTable inside a Window, and the source and DataAdapter for the DataTable defined as follows:
var source = { type: "POST", datatype: "json", datafields: [ { name: 'Id', type: 'int' }, { name: 'Code' }, { name: 'Name' }, { name: 'Description' }, { name: 'Value', type: 'float' }, { name: 'VatRate', type: 'float' } ], id: 'Id', url: endpointURL, cache: false, root: 'data' }; var dataAdapter = new $.jqx.dataAdapter(source, { contentType: 'application/json; charset=utf-8', // Add the parameters to the call to the service formatData: function (data) { // Note that we need to return a JSON string here, not a JSON object return JSON.stringify({ JobSiteID: JobSiteID }) }, downloadComplete: function (data, textStatus, jqXHR) { return data.d; } }
I’ve then got the DataTable being initialized as follows (extra code snipped off the bottom):
$("#tblQuoteItems").jqxDataTable( { theme: 'arbpro', width: '100%', height: '300', source: dataAdapter, pageable: false, editable: true, showToolbar: true, altrows: true, toolbarHeight: 35, columns: [ { text: 'Ref', editable: true, dataField: 'Code', width: 50 }, { text: 'Name', editable: true, dataField: 'Name', width: 200 }, { text: 'Description', editable: true, dataField: 'Description', width: 290 }, { text: 'Value', editable: true, dataField: 'Value', width: 90, cellsFormat: 'F2', cellsalign: 'right' }, { text: 'VAT Rate', editable: true, dataField: 'VatRate', width: 90, cellsFormat: 'F2', cellsalign: 'right' }, ],
Note that I’m using formatData to send the JobSiteID to my service endpoint.
All is working fine, but when I close and re-open the window without changing the JobSiteID (i.e. staying on the same JobSite in my application), the adapter is not calling my service endpoint – it appears to be using cached data. I need it to call the service whenever the window is opened. Is there a setting I’m missing?
Hello James Lavery,
dataAdapter does not cache data. It loads data. It makes another Ajax call when you call its dataBind method again. Otherwise, it does not make Ajax call.
Best Regards,
Peter StoevjQWidgets Team
http://www.jqwidgets.comThanks Peter,
I think the problem is that I’m currently only fully initialising the window once, and then showing the existing window if it’s been initialised.So I need to either trigger another bind, or probably preferably remove the jqxWindow to free up resources when it’s closed.
Is there a way of removing the jqxWindow similar to how one would do it in jQuery, by calling $(this).remove() in its close event?
So taking this question further – clearly i’m Doing Something Wrong!
If close the window using the cross or a Close button on the window, where should I call the dataBind() method on the dataAdapter?
Hi James Lavery,
If you want to remove the window from the DOM, you can use its “destroy” method.
Where to call dataBind – this depends on your own application logic. After you created dataAdapter variable, you can call dataAdapter.dataBind() to data bind the adapter or perform a new data binding.
Best Regards,
Peter StoevjQWidgets Team
http://www.jqwidgets.comHi Peter,
Thanks for your help – as a result I’ve sorted out my problem by calling$("#tblQuoteItems").jqxDataTable('updateBoundData');
when I re-open the window.
-
AuthorPosts
You must be logged in to reply to this topic.