function GetGrid2() { var jqdata = [ { Encode:"20180100", FullName: "BYD", SpecType: "cpu200", UnitName: "台", SecondUnit: "", Qty: "10", UnitCode: "50000", Cost: "35000" }, { Encode:"20180100", FullName: "BYD", SpecType: "cpu200", UnitName: "台", SecondUnit: "", Qty: "10", UnitCode: "50000", Cost: "35000" } ]; //创建jqGrid组件 var $gridTable = $('#gridTable');
//固定列 var model = [ { label: "商品编号", name: "Encode", width: 100, align: 'left', sortable: false }, { label: "商品名称", name: "FullName", width: 130, align: "left", sortable: false }, { label: "规格型号", name: "SpecType", width: 150, align: 'left', sortable: false }, { label: "单位", name: "UnitName", width: 150, align: 'left', sortable: false }, { label: "副单位", name: "SecondUnit", width: 150, align: 'left', sortable: false }, { label: "基本数量", name: "Qty", width: 150, align: 'left', sortable: false }, { label: "单位成本", name: "UnitCode", width: 150, align: 'left', sortable: false }, { label: "成本", name: "Cost", width: 150, align: 'left', sortable: false }];
//动态列 var addmodel = [{ label: "基本数量", name: "SHQty", width: 150, align: 'left', sortable: false }, { label: "可用库存", name: "SHRealQty", width: 150, align: 'left', sortable: false }]; $.each(addmodel, function (key, value) { model.push({ label: value.label, name: value.name, index: key, width: value.width, align: value.align, sortable: value.sortable }); }); //创建jqGrid组件 $gridTable.jqGrid( { datatype: "json", height: $(window).height() - 230.5, autowidth: true, colModel: model, pager: false, rownumbers: true, shrinkToFit: false, gridview: true, footerrow: true, sortname: 'ExecutionDate', sortorder: 'desc', beforeRequest: function () { $("thead th").css("text-align", "center").css("font-weight", "bold"); }, gridComplete: function () { var totalreceivable = $(this).getCol("Receivable", false, "sum"); var totalexpenses = $(this).getCol("Expenses", false, "sum"); var totalbalance = $(this).getCol("Balance", false, "sum"); //合计 $(this).footerData("set", { "ExecutionDate": "合计:", "Receivable": totalreceivable, "Expenses": totalexpenses, "Balance": totalbalance }); $('table.ui-jqgrid-ftable td').prevUntil().css("border-right-color", "#fff"); } }); //将jqdata的值循环添加进jqGrid for (var i = 0; i <= jqdata.length; i++) { $gridTable.jqGrid('addRowData', i + 1, jqdata[i]); } //固定表头合并 var groupHeaders = [ { startColumnName: 'Qty', numberOfColumns: 3, titleText: '所有仓库' } ];
//动态表头 if (1 == 1) { groupHeaders.push({ startColumnName: 'SHQty', numberOfColumns: 2, titleText: '上海仓库' }); } $gridTable.jqGrid('setGroupHeaders', { useColSpanStyle: true, groupHeaders: groupHeaders }); }