jqGrid问题绑定子网格

时间:2010-11-30 17:09:18

标签: jqgrid

我有一个没有正确显示子网格行的jqGrid。当我加载页面时,常规网格行显示正常以及每个网格旁边的加号,但是当我单击加号按钮展开它们时,“正在加载...”消息仍然存在且没有任何反应。我不知道它是否有所作为,但我试图在客户端进行(loadonce:true)。

以下是创建网格的代码:

$("#Grid1").jqGrid({
// setup custom parameter names to pass to server
prmNames: {
    search: null,
    nd: null,
    rows: "numRows",
    page: "page",
    sort: "sortField",
    order: "sortOrder"
},
datatype: function(postdata) {
    $(".loading").show(); // make sure we can see loader text
    $.ajax({
        url: 'WebServices/GetJSONData.asmx/getGridData',
        type: "POST",
        contentType: "application/json; charset=utf-8",
        data: JSON.stringify(postdata),
        dataType: "json",
        success: function(data, st) {
            if (st == "success") {
                var grid = $("#Grid1")[0];
                grid.addJSONData(JSON.parse(data.d));
                //Loadonce doesn't work, have to do its dirty work
                $('#Grid1').jqGrid('setGridParam', { datatype: 'local' });
                //After rows are loaded, have to manually load subgrid rows
                var subgridData = JSON.parse(data.d).subgrid;
                var lista = jQuery("#Grid1").getDataIDs();
                var rowData;
                //Iterate over each row in grid
                for (i = 0; i < lista.length; i++) {
                    //Get current row data
                    rowData = jQuery("#Grid1").getRowData(lista[i]);

                }
            }
        },
        error: function() {
            alert("Error with AJAX callback");
        }
    });
},
// this is what jqGrid is looking for in json callback
jsonReader: {
    root: "rows",
    page: "page",
    total: "totalpages",
    records: "totalrecords",
    cell: "cell",
    id: "id", //index of the column with the PK in it 
    userdata: "userdata",
    repeatitems: true
},
coNames: ['Inv No', 'Amount', 'Store', 'Notes'],
colModel: [
    { name: 'InvNum', index: 'InvNum', width: 200 },
    { name: 'Amount', index: 'Amount', width: 55 },
    { name: 'Store', index: 'Store', width: 50 },
    { name: 'Notes', index: 'Notes', width: 100 }
],
subGrid: true,
subGridModel: [{
    name: ['InvNum', 'Name', 'Qauntity'],
    width: [55, 200, 80],
    params: ['InvNum']
}],
rowNum: 10,
rowList: [10, 20, 50],
pager: '#Div1',
viewrecords: true,
width: 500,
height: 230,
scrollOffset: 0,
loadonce: true,
ignoreCase: true,
gridComplete: function() {
    $(".loading").hide();
}
}).jqGrid('navGrid', '#Div1', { del: false, add: false, edit: false }, {}, {}, {}, { multipleSearch: true });

这里是我在webservice调用中使用的代码,用于创建JSON数据:


IEnumerable orders = getOrders();
IEnumerable items = getItems();

int k = 0;

var jsonData = new
{
    totalpages = totalPages, //--- number of pages
    page = pageIndex, //--- current page
    totalrecords = totalRecords, //--- total items
    rows = (
        from row in orders
        select new
        {
            id = k++,
            cell = new string[] {
                row.InvNum.ToString(), row.Amount.ToString(), row.Store, row.Notes
            }
        }
    ).ToArray(),
    subgrid = (
        from row in items
        select new
        {
            cell = new string[] {
                row.InvNum.ToString(), row.Name, row.Quantity.ToString()
            }
        }
    ).ToArray()
};

result = Newtonsoft.Json.JsonConvert.SerializeObject(jsonData);

0 个答案:

没有答案
相关问题