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.

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
  • DataAdapter cacheing data? #65771

    James Lavery
    Participant

    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?

    DataAdapter cacheing data? #65775

    Peter Stoev
    Keymaster

    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 Stoev

    jQWidgets Team
    http://www.jqwidgets.com

    DataAdapter cacheing data? #65781

    James Lavery
    Participant

    Thanks 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?

    DataAdapter cacheing data? #65793

    James Lavery
    Participant

    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?

    DataAdapter cacheing data? #65828

    Peter Stoev
    Keymaster

    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 Stoev

    jQWidgets Team
    http://www.jqwidgets.com

    DataAdapter cacheing data? #65948

    James Lavery
    Participant

    Hi 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.

Viewing 6 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic.