After using jqgrid\'s setFooterData function to calculate the total amount like in this question , this is my grid and functions:
I made new demo where I used another way to enumerate the cells in the grid (see the answer).
In the demo I modified the code of getTextFromCell
and calculateTotal
functions to the following:
var getTextFromCell = function(cellNode) {
if (cellNode.childNodes[0].nodeName.toUpperCase() === "SELECT") {
var selOptions = $("option:selected", cellNode);
if (selOptions.length>0) {
return selOptions.text();
}
}
return cellNode.childNodes[0].nodeName.toUpperCase() === "INPUT"?
cellNode.childNodes[0].value:
cellNode.textContent || cellNode.innerText;
},
calculateTotal = function() {
var totalAmount = 0,
iAmount=getColumnIndexByName(grid,'amount'),
iStatus=getColumnIndexByName(grid,'status');
var i=0, rows = grid[0].rows, rowsCount = rows.length, row, status;
for(;i<rowsCount;i++) {
row = rows[i];
if (row.className.indexOf('jqgrow') !== -1) {
status = getTextFromCell(row.cells[iStatus]);
if (status === "Confirmed") {
totalAmount += Number(getTextFromCell(row.cells[iAmount]));
}
}
}
grid.jqGrid('footerData','set',{name:'TOTAL Confirmed',amount:totalAmount});
};
Now in the total lines will be displayed the sum of all values from the 'Amount' columns, but only the rows having "Confirmed" in the 'Status' column will be taken in the consideration.