json JQgrid总金额行

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7392987/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-03 17:59:17  来源:igfitidea点击:

JQgrid total amount row

jsonjqgridsum

提问by Madi

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.

iv 在 jqgrid 中看到了@Oleg 的行总和示例,但我尝试应用它但它不起作用我有以下网格我需要计算它的金额值。

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.

奥列格请你帮忙,我试过你的例子,但由于某种原因它没有用。

回答by Oleg

If I understand you correct you want to place in the footer getColand footerDatamethods:

如果我理解你是正确的,你想在页脚getColfooterData方法中放置:

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

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

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

getCol可用于从“量”柱,并且尊重计算所有数字的总和footerData,你可以在底部放置'ID'列中的文本“总计:”和在底部'amount'列。

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

更新:可能你有问题,因为你把代码放在错误的地方。代码最安全的地方是loadComplete事件处理程序。看演示

回答by Etienne Dupuis

Total of a price column:

总价格列:

//Count total for a price column
var total = 0;
$('#table tr').each(function(){

    //cells that contains the price
    var tdprice = $(this).find("td:eq(2)").html();

    //Sum it up!
    if (isNaN(tdprice)){ total += parseInt(tdprice); }
});

alert(total + "$");