Search code examples
jqgrid

Make jqgrid only show single group footer at last row in group


Currently I'm using group and pagination in jqgrid. The data is long and each group might cross a few page in jqgid. I'm apply the group total and it seems the group total exists at every page and the calculate (sum) base on the existing row at current page. In my use case it is misleading, I wish to show group total after last row of each group. I'm using version v5.1.1 (Guriddo jqGrid JS) Is it achievable?

$grid.jqGrid({

            data: dataarray,
            datatype: 'local',
            height: 'auto',
            width: '100%',
            viewrecords: true,
            sortable: true,
            loadonce: true,
            colNames: columnarray,
            colModel: columnmodelarray,
            rownumbers: true,
            grouping: true, 

            rowNum: 20,
            gridview: true, 
            regional : 'en',
            autowidth:true, 
            shrinkToFit:false,
            rowList: [20, 50, 100, 200,400,999999999999],           
            userDataOnFooter: true,
            footerrow:true,
            sortname:sortname,
            sortorder:sortorder,
            colMenu : true,

            pager: pagerid,
            groupingView:groupviewjsondata,
            loadComplete:function()
            {
                //calculate total to put at bottom
                var columncontent={};
                var i=0;
                var lastcolumn='';

                var isshownumber=0;

                $.each(colmodels,function(colno,colobj)
                {
                    if(colobj.datatype=='number' && colobj.withtotal == true)
                    {
                        var tmptotal=0;
                        $.each(rp.result.data,function(row_id,row)
                        {
                            if(typeof row[ colobj['name']] =='string')
                            {
                                row[ colobj['name']]=parseFloat(row[ colobj['name']]);
                            }

                            tmptotal += row[ colobj['name']];
                        });
                        columncontent[colobj['name']]=tmptotal;
                        isshownumber++;

                    }
                    if( isshownumber==1) 
                    {                       
                        columncontent[lastcolumn]='<div style="text-align:right">'+lang('Total')+'</div>';                      
                    }
                    if((colobj.datatype=='date' || colobj.datatype=='string')&& (colobj.hidden===undefined ||colobj.hidden==false) )
                    {
                        lastcolumn=colobj['name'];  
                    }

                });

                $grid.jqGrid('footerData','set',columncontent);

            }
        });

Solution

  • Please check this demo - the total is not per page, but per group see the group value AROUT. The only that I can think is that you provide the data dynamically per page (from server with paging) and not at once - in this case it is as you describe