0

I get a JSON response from the server that I have full access to using loadComplete. Is it possible to be able to access the JSON response using

  1. onSelectRow?
  2. any other custom function defined outside of loadComplete?
Chris E
  • 973
  • 13
  • 26
techlead
  • 779
  • 7
  • 24
  • 44

1 Answers1

1

You can define a variable which will hold the last state of the JSON response returned from the server:

var serverData;
$('#list').jqGrid({
    datatype: 'json',
    // ... other parameters
    loadComplete: function (data) {
        serverData = data; // or serverData = data.rows
        // ...
    },
    onSelectRow: function (id) {
        if (serverData) {
            // here you can access serverData, but you need
            // here probably find the item in the serverData
            // which corresponds the id
        }
    }
});

If you have JSON data for example from the form

{
  "total": "xxx",
  "page": "yyy",
  "records": "zzz",
  "rows" : [
    {"id" :"1", "cell": ["cell11", "cell12", "cell13"]},
    {"id" :"2", "cell": ["cell21", "cell22", "cell23"]},
      ...
  ]
}

then you can save in serverData not the data directly. It could be interesting to save only cell part and save it as the value of the serverData[id]:

var serverData = [];

$('#list').jqGrid({
    datatype: 'json',
    // ... other parameters
    loadComplete: function (data) {
        var i, rows = data.rows, l = rows.length, item;
        for (i = 0; i < l; i++) {
            item = rows[i];
            serverData[item.id] = item.cell;
        }
        // ...
    },
    onSelectRow: function (id) {
        var item = serverData[id]; // the part of data which we need
    }
});

If you use repeatitems: false setting in the jsonReader then you can save in the serverData only the part of the items (selected properties) which represented the row of the server data.

In any way you should save the part of the information from data parameter of loadComplete in some variable defined outside of the loadComplete.

Oleg
  • 220,925
  • 34
  • 403
  • 798
  • can you please take a look at this one? http://stackoverflow.com/questions/8564806/jqgrid-error-when-moving-from-1-page-to-another – techlead Dec 19 '11 at 17:51