JQgrid total amount row

后端 未结 2 1832
广开言路
广开言路 2020-12-03 12:44

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.

相关标签:
2条回答
  • 2020-12-03 13:28

    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 + "$");
    
    0 讨论(0)
  • 2020-12-03 13:41

    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.

    0 讨论(0)
提交回复
热议问题