jqGrid没有加载数据 [英] jqGrid is not loading data

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

问题描述

我将jqGrid用于我的数据表解决方案.下面是配置代码.

I am using jqGrid for my data table solution. Below are the configuration codes.

$(function() {
    $("#submitInput").click(function() {
        alert("I am called...")
        jQuery("#list").jqGrid({
            datatype: "json",
            url: "http://localhost:1201/admin/someURL.htm",
            mtype:"POST",
            height: "auto",
            colNames:["Column 1", "Column 2", "Column 3", "Column 4", "Column 5"],
            colModel:[
                {name:"col1", index:"col1", sortable:true, resizable:false},
                {name:"col2", index:"col2", sortable:true},
                {name:"col3", index:"col3", sortable:false, resizable:false},
                {name:"col4", index:"col4", sortable:true, resizable:false},
                {name:"col5", index:"col5", sortable:true, resizable:false}
            ],
            sortname:'col1',
            sortorder:'asc',
            pager: $('#pager'),
            rowNum:10,
            viewrecords: true,
            rowList:[10,20,30],
            caption: 'Some Grid Values',
            jsonReader: {
                root: "responseData",
                page: "currentPage",
                total: "totalPages",
                records: "totalFetchedRecords",
                repeatitems: true,
                cell: "rowContent",
                id: "rowID"
            },
            gridComplete: function() {
                alert("Loading done...");
            }
        });
    });
});

我的JSON数据采用以下格式:

My JSON data is coming in the following format:

"currentPage":"1","responseData":[
    {"rowContent":["Col1_Val_000001","Col2_Val_1","Col3_Val_1","Col4_Val_1","Col5_Val_1"],"rowID":"Col1_Val_000001"},
    {"rowContent":["Col1_Val_000002","Col2_Val_2","Col3_Val_2","Col4_Val_2","Col5_Val_2"],"rowID":"Col1_Val_000002"}
], "totalFetchedRecords":"50","totalPages":"5"}

在我的HTML中,有一个ID为"submitInput"的按钮和一个ID为"list"的表.

In my HTML, there is a button with id "submitInput" and a table with id "list".

不知何故,此数据未加载到网格中.是什么原因?

Somehow, this data is not loaded into the grid. What is the reason?

推荐答案

可能您不应该在 click 句柄内创建jqGrid.您应该在 click 句柄之外执行一次此操作,然后在处理程序中调用jQuery("list").trigger('reloadGrid').如果开头不应将数据加载到网格中,则可以使用datatype: 'local'作为开头.如果需要,可以使用hide()show() jQuery函数使jqGrid的 div 有时可访问,而有时不可见.在click处理程序内部,您可以相对于setGridParam()datatype更改为'json',然后调用trigger('reloadGrid').在很多情况下,您还需要在调用trigger('reloadGrid')之前更改URL的某些参数(请参阅

Probably you should don't create jqGrid inside of click handle. You should do this one time outside of click handle and call jQuery("list").trigger('reloadGrid') inside of the handler. If at the beginning the data should be not loaded in the grid, you can use datatype: 'local' an the beginning. If it needed, you can makes div with jqGrid sometimes visitable and sometimes invisible using using hide() and show() jQuery functions. Inside of click handler you can change the datatype to 'json' with respect of setGridParam() and then call trigger('reloadGrid'). In a lot of situation you also change some parameters of URL before calling trigger('reloadGrid') (see Should one replace the usage addJSONData of jqGrid to the usage of setGridParam(), and trigger('reloadGrid')?), but probably you need it not in your case.

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

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