I have a Jqgrid with two subgrids and a groupingView(), when my data is loaded from the server into the grid my subgrid does not want to expand. Only when I page or click the refresh button the subgrid does expand, or when I set loadonce:false or take out the groupingView() it wil expand and everything is working fine, but then my export to excel is not showing any data. I want my subgrid to expand when the data is loaded for the first time, not after I refresh or page!
I have have tried:
$MyGrid.jqGrid('setGridParam',{datatype:'json'}).trigger('reloadGrid');
and also tried making a trigger to fire the refresh button on loadComplete()
*$(".ui-icon-refresh").each(function () {
$(this).trigger("click");
});*
This trigger button does work when it's clicked, but it does not fire automatically in the loadComplete() function.
Here is my 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();
});
Function for GroupRowID():
function groupRowID()
{
var jsonSearchString = "";
var sGroupId = <?php echo "'" . $sGroupId . "'" ; ?>;
jsonSearchString = '"GROUPID":"' + sGroupId + '",';
return "{" + jsonSearchString;
}
#tdBotRight
exist on the page initially or you generate it and place it dynamically? Why your code contains outer{ ... }
? The code$("#DataTab_2").jqGrid().setGridParam({ datatype: 'local',..})).trigger("reloadGrid");
is very bad inside ofloadComplete
of the same grid. You use explicitlyloadonce: false
, but try to do close things, but in the wrong way. What is your goal? – UnattendedsubGridOptions: {..., expandOnLoad: false, ...}
. Why subgrids should be expanding? jqGrid send Ajax request to/Ord/WS/OrderWebSummary.php
to load main grid data and then you want to send multiple requests to/Ord/WS/OrderItemSummary.php
for every subgrid? Is it not better to load all subgrid information at the loading of the main grid? – UnattendedgroupRowID()
provide almost no information because$sGroupId
is unknown. Moreover why you need the function which returns something like{"GROUPID":"blabla",
. It's a part of something. It have no meaning along. Good interface would be either to return just$sGroupId
or to return the object{GROUPID:"blabla"}
. One can merge it with other properties using$.extend
. Back to your main question. I recommend you to includeloadError
callback in grid (subgrid). See the answer. – Unattended$sGroupId
as a value, a string, but without any example one can't say that the posted code is correct or wrong. If it's general value then it can contains"
,` and so on. In the case the
groupRowID()` will wrong, butJSON.stringify()
will allays produce correct JSON string. I asked you to post the URL example sent to the server and the server response because without the data one can't solve the problem. If no data are displayed then something is wrong, but one have to analyse every step to find the reason. I can't help you without having more details. – Unattended/Ord/WS/OrderItemSummary.php
. My question was: which request for filling of subgrid will be sent to the server? Which response for filling of subgrid you get from/Ord/WS/OrderItemSummary.php
? Your problem is: no data will be displayed in the subgrid. Isn't so? So one have to analyse the failed request. Either the request is wrong or the response is wrong or the options of subgrid don't corresponds the format of the server response. – UnattendedloadError
to all grids like I suggested in previous comments? What error you see? I see many common problems in your code. The response contains noid
property. Alternatively you can includekey: true
in one column (inITEM
for example) to inform get rowids from the values. You need have unique values in the column. So jqGrid have to assign the values 1,2,3,... as rowid for all grids and subgrids. You will have id duplicates which is not allowed in HTML. – UnattendedidPrefix
in subgrids. You should always useidPrefix
in subgrids. For exampleidPrefix: "s1_" + row_id + "_"
for the subgrids of the first level andidPrefix: "s1_" + row2_id + "_"
for subgrids of the second level. – Unattended