0

This is my jqgrid footerrow code

loadComplete: function() {
            var debit = $("#myDataList").jqGrid('getCol', 'debit', false, 'sum');
            $("#myDataList").jqGrid('footerData', 'set', {category: 'Total:', debit: debit});
            var credit = $("#myDataList").jqGrid('getCol', 'credit', false, 'sum');
            $("#myDataList").jqGrid('footerData', 'set', {category: 'Total:', credit: credit});
        }

I want to cum up two column value debit and credit, my problem now is the total value only sum up the current page but not all.

1 Answers1

1

If you use datatype: "local" or datatype: "json" or datatype: "xml" with loadonce: true then more as one page of data will be saved locally in the grid. The array of data is accessible by $(this).jqGrid("getGridParam", "data"). So you can enumerate all items of internal data and calculate the sum of all elements from "debit" and "credit" columns. Then you can use

$(this).jqGrid("footerData", "set", {
    category: "Total:",
    debit: debit,
    credit: credit
});

The answer and this one contains code fragments with very close work. In your case it will be about the following code (I didn't tested it):

loadComplete: function () {
    var $self = $(this),
        localData = $self.jqGrid("getGridParam", "data"),
        itemCount = localData.length,
        totalCredit = 0,
        totalDebit = 0,
        i,
        item;

    for (i = 0; i < itemCount; i++) {
        item = localData[i];
        totalCredit += parseFloat(litem.credit);
        totalDebit += parseFloat(litem.debit);
    }

    $self.jqGrid("footerData", "set", {
        category: "Total:",
        debit: totalDebit,
        credit: totalCredit
    });
}
Community
  • 1
  • 1
Oleg
  • 220,925
  • 34
  • 403
  • 798
  • Thanks @Oleg, it's helpful , but is it possible to display footer that contain summary only on last page? – yash Jun 10 '16 at 10:24
  • @yash: Not directly, but the footer is just a div which you can hide/show inside of `loadComplete`. – Oleg Jun 10 '16 at 10:26
  • but if i hide div than it not display at the last page too, so what can i do if i want to display only on last page? thanks in advance. – yash Jun 10 '16 at 10:28
  • @yash: jqGrid consist from many dives and tables. You should hide only the footer div. If you would have implementation problem you can post **new question** and I'll post my answer with an example of JavaScript code which do this. – Oleg Jun 10 '16 at 10:41