Jqgrid 3.7不显示Internet Explorer中的行

时间:2010-06-16 14:57:08

标签: asp.net json optimization jqgrid asmx

我正在使用ASP.NET和Jqgrid 3.7进行测试,在firefox中它工作正常,但在IE中它不显示网格中的任何行。

来自网络服务的回复是

{"d":
    {"__type":"jqGrid",
     "total":"1",
     "page":"1",
     "records":"10",
     "rows":[
         {"id":"180","cell":["180","Cultura"]},
         {"id":"61","cell":["61","Deporte"]},
         {"id":"68","cell":["68","Deporte"]},
         {"id":"5","cell":["5","Economía"]},
         {"id":"67","cell":["67","Economía"]},
         {"id":"76","cell":["76","Economía"]},
         {"id":"178","cell":["178","Economía"]},
         {"id":"4","cell":["4","Entrevista"]},
         {"id":"66","cell":["66","Entrevista"]},
         {"id":"78","cell":["78","Entrevista"]}
     ]
    }
}

,电话是

myGrid = $("#list").jqGrid({
    url: 'ws/WsNoticias.asmx/jqObtenerTemas',
    datatype: 'json',
    mtype: 'GET',
    loadBeforeSend: function(XMLHttpRequest) {
        XMLHttpRequest.setRequestHeader("Content-Type", "application/json");
    },
    colNames: ['Id', 'Nombre'],
    colModel: [
        {name: 'Id', index: 'Id', width: 20, align: 'left', editable: false},
        {name: 'Nombre', index: 'Nombre', width: 200, align: 'left', editable: false}
    ],
    rowNum: 10,
    rowList: [5, 10, 200],
    sortname: 'Nombre',
    sortorder: "asc",
    pager: $("#listp"),
    viewrecords: true,
    caption: '',
    width: 600,
    height: 250,
    jsonReader: {
        root: "d.rows",
        page: "d.page",
        total: "d.total",
        records: "d.records"
    }
});

我看不出问题出在哪里......,版本高于3.6和

thegrid.addJSONData(JSON.parse(jsondata.responseText).d);

而不是jsonReader它可以工作。

1 个答案:

答案 0 :(得分:3)

您首先应该使用 URL中的完整路径(以http://开头或至少使用/)。在很多情况下,Internet Explorer在相对URL中工作错误。

更多小的一般性评论。您可以使用ajaxGridOptions: { contentType: 'application/json; charset=utf-8' }而不是loadBeforeSend。其他一些默认值(请参阅http://www.trirand.com/jqgridwiki/doku.php?id=wiki:colmodel_options)也可以删除。

myGrid = $("#list").jqGrid({
    url: 'http://www.ok-soft-gmbh.com/jqGrid/Jqgrid37json.txt',
    datatype: 'json',
    mtype: 'GET',
    ajaxGridOptions: { contentType: 'application/json; charset=utf-8' },
    colModel: [
        { name: 'Id', width: 20 },
        { name: 'Nombre', width: 200 }
    ],
    rowNum: 10,
    rowList: [5, 10, 200],
    sortname: 'Nombre',
    sortorder: "asc",
    pager: $("#listp"),
    viewrecords: true,
    width: 600,
    height: 250,
    jsonReader: {
        root: "d.rows",
        page: "d.page",
        total: "d.total",
        records: "d.records"
    }
});

此外,您可以将JSON数据减少到

{"d":
    {"__type":"jqGrid",
     "total":"1",
     "page":"1",
     "records":"10",
     "rows":[
         ["180","Cultura"],
         ["61","Deporte"],
         ["68","Deporte"],
         ["5","Economía"],
         ["67","Economía"],
         ["76","Economía"],
         ["178","Economía"],
         ["4","Entrevista"],
         ["66","Entrevista"],
         ["78","Entrevista"]
     ]
    }
}

并添加jsonReader poperty单元格的定义:“”:

jsonReader: {
    root: "d.rows",
    page: "d.page",
    total: "d.total",
    cell: "",
    records: "d.records"
}

您可以验证http://www.ok-soft-gmbh.com/jqGrid/Jqgrid37.htmhttp://www.ok-soft-gmbh.com/jqGrid/Jqgrid37Comact.htm在所有标准网络浏览器中都可以正常运行。