简体   繁体   中英

store result of ajax call in jqgrid to local variable

I ca get my jqgrid populating via json returned from server with the code below - partial code

$.extend($.jgrid.nav, {refreshstate: "current"});
    $('#jqgrid').jqGrid({
        mtype:'GET',
        url: 'getdata.json',
        datatype: 'json',
        jsonReader:{
            repeatitems: false,
            id:'guid',
            root: 'productinfo',
            page: function (obj) { return 1; },
            total: function (obj) { return 100; },
            records: function (obj) { return obj.length; }
        },

When user goes to edit a record, I want to display the record selected - since I already got all the data down to populate the jqgrid, i do not want to make another call to my service to obtain the record.

I looked at jsonstring but then got on alert as the document stated that paging may not work as the datatype is switched to local data type.

If i can save the json result returned from server to local var, i could use that local var array to obtain data record for a selected row.

I only show 2 columns in the jqgrid even though my json returned has more elements

This is done inside of backbone view

You can use global ajax events like:

var localVar;
$(document).ajaxSuccess(function(event, XMLHttpRequest, ajaxOptions) {
   if (ajaxOptions.url === 'getdata.json') {
      localVar = XMLHttpRequest.responseText;
   }
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM