如何在jqgrid中获取带有文本框的列的总和

时间:2017-07-19 10:20:02

标签: javascript jqgrid

我有一个jqgrid,如下图所示,我希望获得“数量变量”的总和。列,但列值在文本框中!你可以帮我这样做吗?我想把这笔钱拿到文本框中!

enter image description here

    function grid() {
        debugger
        var subid = $("#cmbProduct").val();
        $('#griddata').html('<table class="table" id="jqgrid"></table>')
        $('#jqgrid').jqGrid({
            url: '/Inventor/GetAllProductsAvailableStocktoStockAdjustmentGrid?SUBID=' + subid,
            datatype: 'json',
            mtype: 'GET',
            //columns names
            colNames: ['ProductId', 'Sub Category', 'Product Code', 'Product Name', 'Available Stock', 'New Stock', 'Qty Varience', 'Stock Loss/Profit','LastUnitPrice1','LastUnitPrice2' ,'LastQty1','LastQty2' , 'Update', /*'Cancel',*/],
            //columns model
            colModel: [
            { name: 'ProductId', index: 'ProductId', hidden: true },
            { name: 'SubCategoryName', index: 'SubCategoryName', align: 'left', width: 250, sortable: false },
            { name: 'Product_ProductCode', index: 'Product_ProductCode', align: 'left', width: 120, sortable: false },
            { name: 'ProductName', index: 'ProductName', align: 'left', width: 230, sortable: false },
            { name: 'AvaiStock', index: 'AvaiStock', align: 'left', width: 80, sortable: false },
            { name: 'New_Stock', index: 'New_Stock', align: 'left', width: 70, sortable: false },
            { name: 'Qty_Varience', index: 'Qty_Varience', align: 'left', width: 80, sortable: false },
            { name: 'Stock_LossorProfit', index: 'Stock_LossorProfit', align: 'left', width: 90, sortable: false },

            { name: 'Update', index: 'Update', align: 'center', width: 90, sortable: false }
            ],
            pager: '#jqgrid',
            rowNum: 10,
            sortname: 'ProductName',
            sortorder: "desc",
            viewrecords: true,
            width: 'auto',
            height: 'auto',
            gridview: true,
            rowNum: 2000,
            rowTotal: 200,
            rowList: [20, 30, 50, 100],
            rownumbers: false,
            rownumWidth: 40,
            loadonce: true,
          //  footerrow: true,
            afterSaveCell: function (rowid, cellname, value, iRow, iCol) {
            },
            subGrid: false,
            gridComplete: function () {
                var ids = jQuery("#jqgrid").jqGrid('getDataIDs');
                for (var i = 0; i < ids.length; i++) {
                    var cl = jQuery("#jqgrid").getRowData(i + 1).ProductId;
                    var cl1 = jQuery("#jqgrid").getRowData(i + 1).AvaiStock;
                    var cl2 = jQuery("#jqgrid").getRowData(i + 1).New_Stock;
                    var cl3 = jQuery("#jqgrid").getRowData(i + 1).Qty_Varience;
                    var cl4 = jQuery("#jqgrid").getRowData(i + 1).Stock_LossorProfit;

                    Ed = '<input style="height:25px;" type="button" value="UPDATE" class="btn btn-success " onclick="UpdatesingleProductPrice(\'' + cl + '\')"/>  '
                    Avs = '<input style="height:25px;" type="text" class="input-Avs form-control col-md-3 center-block input-sm" id="input-Avs-' + cl + '"  value="' + cl1 + '" disabled />  '
                    Nw = '<input style="height:25px;" type="text" class="input-Nw form-control col-md-3 center-block input-sm" id="input-Nw-' + cl + '" onkeyup =calstockadj("' + cl + '") value="0" />  '
                    Qv = '<input style="height:25px;" type="text"  class="input-Qv form-control col-md-3 center-block input-sm" id="input-Qv-' + cl + '" value="' + cl3 + '" disabled/>  '
                    Sl = '<input style="height:25px;" type="text"  class="input-Sl form-control col-md-3 center-block input-sm" id="input-Sl-' + cl + '" value="' + cl4 + '" disabled />  '

                    jQuery("#jqgrid").jqGrid('setRowData', ids[i], { Update: Ed });
                    jQuery("#jqgrid").jqGrid('setRowData', ids[i], { AvaiStock: Avs });
                    jQuery("#jqgrid").jqGrid('setRowData', ids[i], { New_Stock: Nw });
                    jQuery("#jqgrid").jqGrid('setRowData', ids[i], { Qty_Varience: Qv });
                    jQuery("#jqgrid").jqGrid('setRowData', ids[i], { Stock_LossorProfit: Sl });                


                }
            },
        });
    }

2 个答案:

答案 0 :(得分:0)

功能计算(e){

        var sum123 = 0;
            $('#input-Qv-' + e + '').each(function () {
                sum123 += +$(this).val();
            });
        }

答案 1 :(得分:0)

你可以得到这样的总数:

        function ShowToal() {
        var sum = 0;
        $('#griddata').find('td[aria-describedby="grid-table_Qty_Varience"]').each(function () {
            sum += $(this).html();
        });
    }