我有一个带有两个子网格的 Jqgrid 和一个 groupingView(),当我的数据从服务器加载到网格时,我的子网格不想展开。只有当我点击或点击刷新按钮时,子网格才会展开,或者当我设置 loadonce:false 或取出 groupingView()时,它会扩展并且一切正常,但是我导出到excel没有显示任何数据。我希望我的子网格在第一次加载数据时展开,而不是在我刷新或页面之后!
我尝试过:
$MyGrid.jqGrid('setGridParam',{datatype:'json'}).trigger('reloadGrid');
还尝试触发按下 loadComplete()
上的刷新按钮*$(".ui-icon-refresh").each(function () {
$(this).trigger("click");
});*
此触发按钮在单击时可以正常工作,但不会在 loadComplete()功能中自动触发。
这是我的Javascript:
function CreateOrdSummaryTable()
{
if ($("#DataTab_2").length === 0)
{
$("#tdBotRight").html("<table id='DataTab_2' class='dataContent' border='1' align='top'></table>" +
"<div id='PagerDataTab_2'></div>");
}
var $tableOrdSummary = $("#DataTab_2");
$tableOrdSummary.jqGrid({
url: '/Ord/WS/OrderWebSummary.php',
colNames: ["Sum of Order Mass","Customer", "Case", "Associated Mass" ,"Order Mass","Invoiced Mass","Shipped Mass","FGI Mass"],
colModel: [
{ name: "ORDITM", index: "ORDITM", resizable: true, width: 120},
{ name: "CUSTOMER", index: "CUSTOMER", resizable: true, width: 250},
{ name: "CASES", index: "CASES", summaryTpl: "<i>Order Group Total:</i>", summaryType: "sum", resizable: true, width: 250},
{ name: "ASSMASS", index: "ASSMASS", summaryTpl: "<i>{0}</i>", summaryType: "sum", resizable: true, width: 165, formatter: "integer"},
{ name: "ORDMASS", index: "ORDMASS", summaryTpl: "<i>{0}</i>", summaryType: "sum", resizable: true, width: 115, formatter: "integer"},
{ name: "DIST", index: "DIST", summaryTpl: "<i>{0}</i>", summaryType: "sum", resizable: true, width: 130, formatter: "integer"},
{ name: "WIP", index: "WIP", summaryTpl: "<i>{0}</i>", summaryType: "sum", resizable: true, width: 130, formatter: "integer"},
{ name: "MDB", index: "MDB", summaryTpl: "<i>{0}</i>", summaryType: "sum", resizable: true, width: 110, formatter: "integer"}
],
pager: jQuery("#PagerDataTab_2"),
shrinkToFit: false,
autoWidth: false,
caption: "Order Summary",
height: "100%",
rowNum: 1000,
//rowList: [50,100,200],
loadonce: false, //This is to get the Paging to turn on if set to (true)
gridview: true,
footerrow: true,
userDataOnFooter: true,
grouping : true,
groupingView : {
groupField : ["ORDITM"],
groupColumnShow : [true],
groupText: [ // user the name of a column with curly braces to use it in a summary expression.
// {0} is the formula placeholder for the column (defined by the summaryType property
"<i><b>{0} - {1} Order(s)</b></i>"
],
showSummaryOnHide: true,
groupSummary : [true],
groupCollapse : false
},
loadComplete: function () {
var AssSum = parseInt($tableOrdSummary.jqGrid('getCol', 'ASSMASS', false, 'sum'));
var OrdSum = parseInt($tableOrdSummary.jqGrid('getCol', 'ORDMASS', false, 'sum'));
var InvSum = parseInt($tableOrdSummary.jqGrid('getCol', 'DIST', false, 'sum'));
var ShpSum = parseInt($tableOrdSummary.jqGrid('getCol', 'WIP', false, 'sum'));
var FGISum = parseInt($tableOrdSummary.jqGrid('getCol', 'MDB', false, 'sum'));
$tableOrdSummary.jqGrid('footerData', 'set',
{
CASES: '<i><b>Grand Total:</b></i>',
ASSMASS: AssSum,
ORDMASS: OrdSum,
DIST: InvSum,
WIP: ShpSum,
MDB: FGISum
});
},
postData: {
"GroupID": function() {
return groupID();
}
},
subGrid: true,
subGridOptions: {
"plusicon" : "ui-icon-triangle-1-e",
"minusicon" : "ui-icon-triangle-1-s",
"openicon" : "ui-icon-arrowreturn-1-e",
"expandOnLoad" : false,
"reloadOnExpand" : true,
"selectOnExpand" : true
},
subGridRowExpanded: function(subgrid_id, row_id) {
var subgrid_table_id, pager_id;
subgrid_table_id = subgrid_id + "_t";
pager_id = "p_" + subgrid_table_id;
$("#"+subgrid_id).html("<table id='"+subgrid_table_id+"' class='scroll'></table><div id='"+pager_id+"' class='scroll'></div>");
jQuery("#"+subgrid_table_id).jqGrid({
url:"/Ord/WS/OrderItemSummary.php",
datatype: "json",
colNames: ["Item", "RFD Date","Associated Mass", "Order Mass", "Invoiced Mass", "Shipped Mass", "FGI Mass"],
colModel: [
{ name: "ITEM", index: "ITEM", resizable: true, width: 60},
{ name: "RFDDATE", index: "RFDDATE", summaryTpl : "<i>Total:</i>", summaryType: "sum", resizable: true, width: 135},
{ name: "ASSMASS", index: "ASSMASS", summaryTpl: "<i>{0}</i>", summaryType: "sum", resizable: true, width: 180, formatter: "integer"},
{ name: "ORDMASS", index: "ORDMASS", summaryTpl: "<i>{0}</i>", summaryType: "sum", resizable: true, width: 115, formatter: "integer"},
{ name: "DIST", index: "DIST", summaryTpl: "<i>{0}</i>", summaryType: "sum", formatter: "integer", resizable: true, width: 130},
{ name: "WIP", index: "WIP", summaryTpl: "<i>{0}</i>", summaryType: "sum", formatter: "integer", resizable: true, width: 130},
{ name: "MDB", index: "MDB", summaryTpl: "<i>{0}</i>", summaryType: "sum", formatter: "integer", resizable: true, width: 115}
],
rowNum:50,
pager: pager_id,
shrinkToFit: false,
autoWidth: false,
height: '100%',
caption: "Item Summary",
// footerrow: true,
// userDataOnFooter: true,
grouping : true,
groupingView : {
groupField : ["ITEM"],
groupColumnShow : [false],
groupText: [ // user the name of a column with curly braces to use it in a summary expression.
// {0} is the formula placeholder for the column (defined by the summaryType property
"<i><b>Item(s): {0}</b></i>"
],
groupOrder: ["asc"],
groupSummary : [true],
groupCollapse : false,
groupDataSorted : true
},
loadComplete: function () {
// var InvSum = parseInt(jQuery("#"+subgrid_table_id).jqGrid('getCol', 'DIST', false, 'sum'));
// var ShpSum = parseInt(jQuery("#"+subgrid_table_id).jqGrid('getCol', 'WIP', false, 'sum'));
// var FGISum = parseInt(jQuery("#"+subgrid_table_id).jqGrid('getCol', 'MDB', false, 'sum'));
// var AssSum = parseInt(jQuery("#"+subgrid_table_id).jqGrid('getCol', 'ASSMASS', false, 'sum'));
// var OrdSum = parseInt(jQuery("#"+subgrid_table_id).jqGrid('getCol', 'ORDMASS', false, 'sum'));
// jQuery("#"+subgrid_table_id).jqGrid('footerData', 'set',
// {
// RFDDATE: '<i><b>Grand Total:</b></i>',
// ASSMASS: AssSum,
// ORDMASS: OrdSum,
// DIST: InvSum,
// WIP: ShpSum,
// MDB: FGISum
// });
},
postData: {
"GroupRwID": function() {
var myString = onRowSelected(row_id);
var finalString = groupRowID() + myString;
//console.log(finalString);
return finalString;
}
},
subGrid: true,
subGridOptions: {
"plusicon" : "ui-icon-triangle-1-e",
"minusicon" : "ui-icon-triangle-1-s",
"openicon" : "ui-icon-arrowreturn-1-e",
"expandOnLoad" : false,
"reloadOnExpand" : true,
"selectOnExpand" : true
},
subGridRowExpanded: function(subgrid2_id, row2_id) {
var subgrid_table_id2, pager_id2;
subgrid_table_id2 = subgrid2_id + "_t";
pager_id = "p_" + subgrid_table_id2;
$("#"+subgrid2_id).html("<table id='"+subgrid_table_id2+"' class='scroll'></table><div id='"+pager_id2+"' class='scroll'></div>");
jQuery("#"+subgrid_table_id2).jqGrid({
url:"/Ord/WS/OrderCaseSummary.php",
datatype: "json",
colNames: ["Case", "Associated Mass"],
colModel: [
{ name: "CASES", index: "CASES", summaryTpl : "<i>Total:</i>", summaryType: "sum", key: true, resizable: true, width: 130},
{ name: "ASSMASS", index: "ASSMASS", summaryTpl: "<i>{0}</i>", summaryType: "sum", resizable: true, width: 180, formatter: "integer"}
],
rowNum:50,
pager: pager_id,
shrinkToFit: false,
autoWidth: false,
height: '100%',
caption: "Cases Summary",
postData: {
"CaseSum": function() {
var selRwData = '"CASES":"' + cases + '",' + '"ORDITM":"' + ordItm + '",' + '"CUSTOMER":"' + customer + '",' + '"ASSMASS":"' + assMass + '"' +"}";
var finalStr = groupRowID() + selRwData;
return finalStr;
}
}
});
$('#'+subgrid_table_id2).addClass("subGrids");
}
});
$('#'+subgrid_table_id).addClass("subGrids");
}
});
$tableOrdSummary.jqGrid("navGrid","#PagerDataTab_2",
{edit:false,add:false,del:false, refreshstat:"current"},
{},
{},
{},
{multipleSearch:false, multipleGroup:false, showQuery: false}
);
}
function ordSummaryView()
{
$("#DataTab_2").jqGrid('setGridParam',{datatype:'json'}).trigger('reloadGrid'); //This makes the call to refresh the grid.
}
function onRowSelected(rowId)
{
var $tableOrdSummary = $("#DataTab_2");
var rowData = $tableOrdSummary.jqGrid ('getRowData', rowId);
cases = rowData.CASES;
customer = rowData.CUSTOMER;
assMass = rowData.ASSMASS;
ordItm = rowData.ORDITM;
var selRwData = '"CASES":"' + cases + '",' + '"ORDITM":"' + ordItm + '",' + '"CUSTOMER":"' + customer + '",' + '"ASSMASS":"' + assMass + '"' +"}";
return selRwData;
}
function getTotals()
{
var $tableOrdSummary = $("#DataTab_2");
ids = $tableOrdSummary.jqGrid('getDataIDs');
int = 0;
for (var i = 0; i < ids.length; i++)
{
var rowId = ids[i];
var rowData = $tableOrdSummary.jqGrid ('getRowData', rowId);
var distTotal = rowData.DIST;
int += parseInt(distTotal);
}
return int;
}
$(document).ready(function()
{
CreateOrdSummaryTable();
});
GroupRowID()的功能:
function groupRowID()
{
var jsonSearchString = "";
var sGroupId = <?php echo "'" . $sGroupId . "'" ; ?>;
jsonSearchString = '"GROUPID":"' + sGroupId + '",';
return "{" + jsonSearchString;
}
答案 0 :(得分:1)
按照您的示例,如果您将此代码添加到主网格选项中,您的子网格将在loadComplete上打开
loadComplete: function(){$(".ui-widget-content.jqgrow.ui-row-ltr td a").click()},
您可以在此处查看:https://jsfiddle.net/f4vosxqo/1/
答案 1 :(得分:0)
除了S.Pini的答案,请使用gridComplete而不是loadComplete。每次发出服务器请求并加载网格时,loadComplete都会触发此差异,gridComplete仅在所有加载进程完成后触发一次。代码示例:
gridComplete: function(){$(".ui-widget-content.jqgrow.ui-row-ltr td a").click()},