jqGrid 不显示 JSON 数据 [英] jqGrid not displaying JSON data

查看:20
本文介绍了jqGrid 不显示 JSON 数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已阅读有关此问题的一些先前问题和答案,但不明白为什么不适合我.我可以看到网格,但它的空白和萤火虫不会给我任何错误.

我的 JSON 数据是这种形式

{"COLUMNS":["ID","MEMO"],"DATA":[[1,"test"],[2,"test1"],[3,"test2"]]}

我已经使用 )

I've read some of the previous question and answers about this issue but couldn't understand why is not working for me. I can see the grid but its empty and firebug don't give me any errors.

My JSON data is in this form

{"COLUMNS":["ID","MEMO"],"DATA":[[1,"test"],[2,"test1"],[3,"test2"]]} 

I've tested that data using The JSON Validator and it pass

my init code with the jsonReader

jQuery("#invoices").jqGrid({
    url:'/bob/index.cfm/invoices/read?format=json',
    datatype: "json",
    colNames:['id','memo'],
    colModel:[
        {name:'id', width:255},
        {name:'memo', width:290}
    ],
    rowNum:10,
    rowList:[10,20,30],
    pager: '#invoicespager',
    sortname: 'id',
    viewrecords: true,
    sortorder: "desc",
    caption:"JSON Example",
    jsonReader: {
        repeatitems: false,
        id: "Id",
        root: function (obj) { return obj; },
        page: function (obj) { return 1; },
        total: function (obj) { return 1; },
        records: function (obj) { return obj.length; }
    }       

});
jQuery("#invoices").jqGrid('navGrid','#invoicespager',{edit:false,add:false,del:false});

解决方案

The most JSON data can be read by jqGrid. You should just use the corresponding jsonReader. To read your JSON data you can use

jsonReader: {
    repeatitems: true,
    id: "0",
    cell: "",
    root: "DATA",
    page: function() { return 1; },
    total: function() { return 1; },
    records: function(obj) { return obj.length; }
}

If you reduce the empty place in your grid with height: 'auto' you will see the following:

(see the demo)

这篇关于jqGrid 不显示 JSON 数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆