Search code examples
asp.netjsonpaginationjqgridgrouping

jqGrid Group summary not showing total sum with paging


This is my first post in this forum, so please, be patient with me.

I need to set my summary to show the sum of all rows in my grid, even the rows that are inside other pages - the absolute sum of values.

I was searching for it, and I saw a lot of people with this problem, so I don't think it is a problem with my code. It sounds more like a design in the grouping mechanism itself, otherwise I don't know.

But, to be clear, I think I need to make a call to server side to get the sum from there, is this possible? If so, how should I do it with json?

I was thinking about using the formatter option, but then it is triggered line by line, and I don't think this is the idea because the sum will come entire in the first call.

Any suggestions?

Thanks !!!


Solution

  • You can define a custom summaryType function to display your sum. According to the documentation for summaryType:

    The option can be defined as function. If defined we pass three parameters to it - the current value, the name and the record object. The function should return value. Note that this value will be used again for the group value until it changes.

    For example, you could retrieve a totalSumRecord when the page is loaded - it would be a bad idea to make an AJAX call directly from the formatter - and then just display the appropriate value in the formatter:

    function myCustomSummary(val, name, record) {
        return totalSumRecord[name];
    }
    
    jQuery("#grid").jqGrid({ 
      ...
      colModel : [
         {..},
         {name:'myColumn',
          index:'myColumn', 
          width:80, 
          align:"right", 
          sorttype:'number',
          formatter:'number',
          summaryType:myCustomSummary},
         ...
      ],
      ...
    });
    


    Update

    There is a bug in jqGrid 4.4 where functions are not allowed as a summary type. If this affects you, here is the fix.