Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JQgrid total amount row

Tags:

json

sum

jqgrid

iv seen an example by @Oleg for row total sum in jqgrid but i tried to apply it and it wont work i have the following grid i need to calculate the amount value for it.

colNames: ['ID', 'FTE', 'Workload'],
    colModel: [
                { name: 'ID', index: 'ID', width: 200, align: 'left', hidden: true },

                { name: 'FTEValue', index: 'FTEValue', width: 200, align: 'left', formatter: 'number' },
                { name: 'Workload', index: 'Workload', width: 200, align: 'left' },



    caption: "Activity FTE",
    gridview: true,
    rownumbers: true,
    rownumWidth: 40,
    scroll: 0,
    rowNum: 100,
    sortname: 'ID',
    pager: '#pager',
    sortorder: "asc",
    viewrecords: true,
    autowidth: true,
    height: '100%',
    footerrow: true,
    jsonReader: { root: "GridData", page: "CurrentPage", total: "TotalPages", records: "TotalRecords", repeatitems: false, id: "0" }
};



DutyFTEGrid.prototype.SetupGrid = function (selector) {
    jQuery(selector).html('<table id="grid"></table><div id="pager"></div>');
    var grid = jQuery("#grid").jqGrid(this.gridConfiguration);

    jQuery("#grid").jqGrid('navGrid', '#pager',
    { edit: false, add: false, search: false }, {}, {},
    { // Delete parameters
        ajaxDelOptions: { contentType: "application/json" },
        mtype: "DELETE",
        serializeDelData: function () {
            return ""; 
        },
        onclickSubmit: function (params, postdata) {
            params.url = serviceURL + 'DutyFTE(' + encodeURIComponent(postdata) + ')/';
        }
    });

    var grid = $("#grid");
    var sum = grid.jqGrid('getCol', 'FTE', false, 'sum');
    grid.jqGrid('footerData', 'set', { DriverEn: 'Total FTE:', FTEValue: sum });
};

Oleg your help please, i have tried your example but it didnt work for some reason.

like image 574
Madi Avatar asked Sep 12 '11 19:09

Madi


1 Answers

If I understand you correct you want to place in the footer getCol and footerData methods:

var grid = $("#list"),
    sum = grid.jqGrid('getCol', 'amount', false, 'sum');

grid.jqGrid('footerData','set', {ID: 'Total:', amount: sum});

The getCol can be used to calculate the sum of all numbers from the 'amount' column and with respect of footerData you can place at the bottom of the 'ID' column the text "Total:" and at the bottom of 'amount' column.

UPDATED: Probably you have problems because you place the code in the wrong place. The most safe place for the code is loadComplete event handler. Look at the demo.

like image 141
Oleg Avatar answered Oct 19 '22 01:10

Oleg