jgGrid将不会加载json数据 [英] jgGrid will not load json data

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

问题描述

我正在将jqGrid用于一个项目.网格初始化没有问题,但是当我尝试用JSON填充网格时,就没有爱意了.

I'm utilizing jqGrid for a project. The grid initializes with no problems, but when I try to populate it with JSON, no love.

HTML:

<table id="search-results"></table>
<div id="search-pagination"></div>

JS:

 //init jqGrid, no problems here


var grid = jQuery('#search-results');

grid.jqGrid({
    dataType: 'local',
    jsonReader: {
        cell: '', //this allows us to ignore the 'cell' property in the response json
        id: 0 //this defines the index in the row that contains the unique id for the row
    },
    colNames:['OrderID', 'First Name', 'Last Name', 'Maiden Name', 'Insco Code', 'Origin', 'Status', 'Appointment', 'Agent Name', 'Hprof/Interviewer', 'Case Date', 'Hprof/Interviewer', 'Street Address', 'Province', 'City', 'Branch #', 'Policy #'],
    colModel:[
        { name: 'Order.ORDERID', index: 'Order.ORDERID', sortable: true, width: '100px', frozen: true},
        { name: 'Applicant.LASTNAME', index: 'Applicant.LASTNAME', sortable: true, width: '100px', frozen: false},
        { name: 'Applicant.FIRSTNAME', index: 'Applicant.FIRSTNAME', sortable: true, width: '100px', frozen: false},
        { name: 'ApplicantMaidenName', index: 'ApplicantMaidenName', sortable: true, width: '100px', frozen: false},
        { name: 'InsCoCode.DESCRIPTION', index: 'InsCoCode.DESCRIPTION', sortable: true, width: '100px', frozen: false},
        { name: 'Order.ORIGIN', index: 'Order.ORIGIN', sortable: true, width: '100px', frozen: false},
        { name: 'MedCase.STATUS', index: 'MedCase.STATUS', sortable: true, width: '100px', frozen: false},
        { name: 'MedCase.PERFORMEDDATE', index: 'MedCase.PERFORMEDDATE', sortable: true, width: '100px', frozen: false},
        { name: 'AgentFullName', index: 'AgentFullName', sortable: true, width: '100px', frozen: false},
        { name: 'ExaminerFullName', index: 'ExaminerFullName', sortable: true, width: '100px', frozen: false},
        { name: 'MedCase.DATEORDERED', index: 'MedCase.DATEORDERED', sortable: true, width: '100px', frozen: false},
        { name: 'Exam.FOLLOWUPDATE', index: 'Exam.FOLLOWUPDATE', sortable: true, width: '100px', frozen: false},
        { name: 'ApplicantStreetAddress', index: 'ApplicantStreetAddress', sortable: true, width: '100px', frozen: false},
        { name: 'Applicant.ADDR1_STATE', index: 'Applicant.ADDR1_STATE', sortable: true, width: '100px', frozen: false},
        { name: 'Applicant.ADDR1_CITY', index: 'Applicant.ADDR1_CITY', sortable: true, width: '100px', frozen: false},
        { name: 'MedCase.MEDICALCOMPANYID', index: 'MedCase.MEDICALCOMPANYID', sortable: true, width: '100px', frozen: false},
        { name: 'Order.POLICYNUMBER', index: 'Order.POLICYNUMBER', sortable: true, width: '100px', frozen: false}

    ],
    rowNum:20,
    rowList:[10,20,30],
    pager: '#search-pagination',
    sortname: 'Order.ORDERID',
    viewrecords: true,
    sortorder: "desc",
    mtype: 'POST',
    autowidth: true,
    shrinkToFit: false
});

grid.jqGrid('setFrozenColumns');

    //trying to load grid now, no luck

    grid.jqGrid('setGridParam', {
        url: '/fasttrack/search?' + form.serialize(),
    dataType: 'json'
    }).trigger('reloadGrid');

JSON响应:

{
"page": 1,
"total": 5,
"records": 100,
"rows": [
    [
        0,
        "two0",
        "three0",
        "four0",
        "five0",
        "six0",
        "seven0",
        "eight0",
        "nine0",
        "ten0",
        "eleven0",
        "twelve0",
        "thirteen0"
    ],
    [
        1,
        "two1",
        "three1",
        "four1",
        "five1",
        "six1",
        "seven1",
        "eight1",
        "nine1",
        "ten1",
        "eleven1",
        "twelve1",
        "thirteen1"
    ],
    [
        2,
        "two2",
        "three2",
        "four2",
        "five2",
        "six2",
        "seven2",
        "eight2",
        "nine2",
        "ten2",
        "eleven2",
        "twelve2",
        "thirteen2"
    ],
    [
        3,
        "two3",
        "three3",
        "four3",
        "five3",
        "six3",
        "seven3",
        "eight3",
        "nine3",
        "ten3",
        "eleven3",
        "twelve3",
        "thirteen3"
    ],
    [
        4,
        "two4",
        "three4",
        "four4",
        "five4",
        "six4",
        "seven4",
        "eight4",
        "nine4",
        "ten4",
        "eleven4",
        "twelve4",
        "thirteen4"
    ],
    [
        5,
        "two5",
        "three5",
        "four5",
        "five5",
        "six5",
        "seven5",
        "eight5",
        "nine5",
        "ten5",
        "eleven5",
        "twelve5",
        "thirteen5"
    ]
]

}

网格不会填充新数据.我究竟做错了什么?我已经阅读了文档,并看了几个不同的示例.

The grid does not populate with the new data. What am I doing wrong? I've read the docs and looked several different examples.

推荐答案

您的主要错误是使用dataType选项而不是datatype.

Your main error is the usage of dataType option instead of datatype.

此外,我不建议您使用具有"."的列名.您可以使用名称中具有"."index.

Additionally I would don't recommend you to use column names having ".". You can use index having "." in the name.

这篇关于jgGrid将不会加载json数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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