6

Hii Guys!! I displayed data in jqgrid and enabled ' footerrow: true' in jqgrid Now as per my need i want to show the sum of particular column on footer Row...Plz guys Help me as I am using Jqgrid For first time ...

Thanks in advance....

vikas
  • 101
  • 1
  • 3
  • 16
  • Look [here](http://stackoverflow.com/a/2820563/315935) for the answer and [here](http://stackoverflow.com/search?q=user%3A315935+footerrow) for more examples on the same subject which I answered before. – Oleg Jan 23 '13 at 14:36

1 Answers1

17

If you want to sum the values which are in the jqGrid, you can do that in JavaScript (preferably in gridComplete event):

$('#gridId').jqGrid({
    ...
    footerrow: true,
    gridComplete: function() {
        var $grid = $('#gridId');
        var colSum = $grid.jqGrid('getCol', '<Your column name>', false, 'sum');
        $grid.jqGrid('footerData', 'set', { 'Your column name>: colSum });
    }
});

If you need to calculate the sum on the server side, then you must enable userDataOnFooter option first:

$('#gridId').jqGrid({
    ...
    footerrow : true,
    userDataOnFooter : true
});

And then include the sum in your server response. For exmple in case of JSON it should look like this:

{
    total: x,
    page: y,
    records: z,
    rows : [
        ...
    ],
    userdata: { <Your column name>: <sum counted on server side> }
}

You can also take a look at live example available on jqGrid Demos page (you should choose "New in Version 3.5" and then "Summary Footer Row").

tpeczek
  • 23,867
  • 3
  • 74
  • 77
  • Here is the code that i added but its not working Sir rowNum: 10, rowList: [10, 20, 30], pager: '#UsersGridPager', sortname: 'UserID', viewrecords: true, sortorder: 'asc', autowidth: true, toppager: true, footerrow: true, gridComplete: function() { var $grid = $('#UsersGrid'); var colSum = $grid.jqGrid('getCol', '', false, 'sum'); $grid.jqGrid('footerData', 'set', { 'Balance>: colSum' }); } – vikas Jan 23 '13 at 15:06
  • @vikas I believe I got you confused with the '<' and '>' brackets, your code should be more like this: gridComplete: function() { var $grid = $('#UsersGrid'); var colSum = $grid.jqGrid('getCol', 'Balance', false, 'sum'); $grid.jqGrid('footerData', 'set', { Balance: colSum }); } – tpeczek Jan 23 '13 at 15:12
  • How cam i use on click function on total record? – Shashank Sharma Aug 20 '20 at 10:25