I am trying to create a jqgrid table with three footer rows to display a total at the end of each grid. Following the guidance in this helpful post from Oleg on How to create two footer rows in jqgrid, I was able to modify the code provided to show three totals lines. It works perfectly on the initial data load, but after clicking on next page or any other action, one of the totals is repeated causing me to lose the second total.
Below is my modified code:
loadComplete: function () {//for showing default edit
var $this = $(this), ids = $this.jqGrid('getDataIDs'), i, l = ids.length;
//In order to have three totals
var $this = $(this),
$footerRow = $(this.grid.sDiv).find("tr.footrow"),
$secondFooterRow,$thirdFooterRow;
var f = '$'+{!optyObj.Otter_FFA_Total_Before_GST__c};
var m = '$'+{!optyObj.Otter_FFA_Grand_Total_GST__c};
var l = '$'+{!optyObj.Otter_FFA_Grand_Total_After_GST__c};
$secondFooterRow = $(this.grid.sDiv).find("tr.myfootrow");
$thirdFooterRow = $(this.grid.sDiv).find("tr.myfootrow");
if ($secondFooterRow.length === 0) {
// add second row of the footer if it's not exist
$secondFooterRow = $footerRow.clone();
$secondFooterRow.removeClass("footrow").addClass("myfootrow ui-widget-content");
$secondFooterRow.children("td").each(function () {
this.style.width = ""; // remove width from inline CSS
});
$secondFooterRow.insertAfter($footerRow);
}
if ($thirdFooterRow.length === 0) {
// add third row of the footer if it's not exist
$thirdFooterRow = $secondFooterRow.clone();
$thirdFooterRow.removeClass("footrow").addClass("myfootrow ui-widget-content");
$thirdFooterRow.children("td").each(function () {
this.style.width = ""; // remove width from inline CSS
});
$thirdFooterRow.insertAfter($secondFooterRow);
}
//FIRST FOOTER ROW
$this.jqGrid("footerData", "set", {Description1__c: "Total EX GST:", Otter_FFA_Total_Price__c:f});
//$this.jqGrid("footerData", "set", {Description1__c: "Total XXX GST:", Otter_FFA_Total_Price__c:f});
//SECOND FOOTER ROW
$secondFooterRow.find(">td[aria-describedby=" + this.id + "_Description1__c]").text("GST:");
$secondFooterRow.find(">td[aria-describedby=" + this.id + "_Otter_FFA_Total_Price__c]").text(m);
//THIRD FOOTER ROW
$thirdFooterRow.find(">td[aria-describedby=" + this.id + "_Description1__c]").text("Total INC GST:");
$thirdFooterRow.find(">td[aria-describedby=" + this.id + "_Otter_FFA_Total_Price__c]").text(l);
}
Here is how it looks on the first load of the page:
Total EX GST: $1,141.12
GST: $114.14
Total INC GST: $1255.26
Page
2 of 2
View 11 - 12 of 12
And here is how it appears when I click on next page or take another action:
Total EX GST: $1,141.12
Total INC GST: $1255.26
Total INC GST: $1255.26
Page
2 of 2
View 11 - 12 of 12
Any advice would be greatly appreciated. I'm using this jqgrid in Salesforce, although ultimately it's just an HTML page. Unfortunately, as a new member in the community, I can't upload images.
Thanks.