0

I have the json below and I am trying to get is display onto my jqgrid. I have the following jsonReader

jsonReader : {
            repeatitems: false,
            root: "abc",
            page: function (obj) { return 1; },
            total: function (obj) { return 1; },
            records: function (obj) { return obj.length; }
        },

column model:

colModel:[
            {name:'num'},
            {name:'seq'},
            {name:'status'},
            {name:'transTime'},
            {name:'sd'},    
            {name:'total'},
            {name:'xys'}
        ],

Json:

{
    "xys": 3,
    "abc": [
        {
            "time": null,
            "num": "1234",
            "seq": 2,
            "status": "X",
            "transTime": null
        },
        {
            "time": null,
            "num": "4567",
            "seq": 1,
            "status": "Y",
            "transTime": null
        }
    ],
    "sd": "7895",
    "total": 5
}

only the num, seq and status got populated with data, but not transTime, sd, total and xys

any ideas and pointer?

onelazyguy
  • 41
  • 2
  • 9
  • `sd`, `total` and `xys` are not a property of `abc` array. How you want to display the items in the grid? Duplicate in every row in the corresponding column? `transTime` is empty and will be not displayed as "null" string, just as an empty string "". – Oleg Jul 29 '14 at 19:57
  • Thanks Oleg! I want to display all of the data coming back in that JSON. I want to display the xys, sd, total and abc array onto the grid. I understand that time and transTime is null so they do not get display. I want to be able to display xys, sd, and total along with abc array – onelazyguy Jul 29 '14 at 20:05
  • The most easy way would be to place `sd`, `total` and `xys` properties as the properties of `abc` items. You can additionally change `"transTime": null` to `"transTime": "null"`. Do you can do this on the server side? If not, then one can do the changes of input data *on the client side* inside of `beforeProcessing` callback. If you will have implementation problems I can show you how one can do this. – Oleg Jul 29 '14 at 20:17
  • Thanks Oleg! Can you please show me how? JSON returns from server is fixed and I cannot make the change. – onelazyguy Jul 29 '14 at 20:19

1 Answers1

0

If you have to read the JSON data and can't change the data on the server side you can makes small transformation of the data returned from the server on the client side inside of beforeProcessing callback. The demo do this and displays the following results

enter image description here

It uses the following code

loadonce: true,
jsonReader: { root: "abc" },
beforeProcessing: function (data) {
    var root = data.abc, i, item, cItems = root.length;
    for (i = 0; i < cItems; i++) {
        item = root[i];
        item.sd = data.sd;
        item.id = $.jgrid.randId();
        item.total = data.total;
        item.xys = data.xys;
        if (item.transTime === null) {
            item.transTime = "null";
        }
    }
}
Oleg
  • 220,925
  • 34
  • 403
  • 798
  • Oleg, I am getting the following error: Uncaught TypeError: Cannot read property 'id' of undefined jquery.jqGrid.min.js:66 – onelazyguy Jul 29 '14 at 20:54
  • @user3420947: **Which version of jqGrid you use?** I included `item.id = $.jgrid.randId();` line in the code, but it's not required. You should always use `jquery.jqGrid.src.js` instead of `jquery.jqGrid.min.js` if you have an error and post the line number in SRC-version of jqGrid. – Oleg Jul 29 '14 at 21:14
  • I use jquery.jqGrid.min.js version 4.2.0. I changed to jquery.jqGrid.src.js and I still get Uncaught TypeError: Cannot read property 'id' of undefined jquery.jqGrid.src.js:1281 – onelazyguy Jul 29 '14 at 21:23
  • @user3420947: I suppose that you don't used `item.id = $.jgrid.randId();` line in `beforeProcessing`. I don't recommend you to use so old version of jqGrid. It was published in 2011. In any way [the modified demo](http://www.ok-soft-gmbh.com/jqGrid/user3420947_.htm) works too with jqGrid 4.2.0. If you will still have the same error with your data you can include `cell: false` property in `jsonReader`. – Oleg Jul 29 '14 at 22:33