简体   繁体   中英

adding a jqgrid column that is a result of two other columns

I want to sum the column values of a jqGrid table.I have four columns in my jqGrid "SL", "Item", "Quantity", "Rate","Amount" ,where Amount is the result of Quantity*Rate this multiplication is not a query retrieved data.It is done inside the javascript code.Now I want to sum the amount column.Summation is showing correctly.I've checked it with an alert but when I tried to set it on footer row $grid.jqGrid('footerData', 'set', { 'amountcalculate': parseFloat(colSum)}); it is showing NAN .why is it not working.I have used footer row earlier and did summation.It worked perfectly.When I tried to add the column value which is a result of two other columns then it does not work. Here is my code

  subGrid : true,
        subGridRowExpanded: function (subgridId, rowid) {
            var subgridTableId = subgridId + "_t";
            $("#" + subgridId).html("<table id='" + subgridTableId + "'></table>");
            $("#" + subgridTableId).jqGrid({
                datatype: "json",
                    url: "/bbbb/regfgfgfisterFgshGood        /listReceivableOrderDetails?id=" + rowid,
                     colNames: ["SL", "Item", "Quantity", "Rate","Amount"],
                       colModel: [
                    {name: "sl", width: 40, align: 'center'},
                    {name: "item", width: 230, align: 'left'},
                    {name: "quantity", width: 100, align: 'center'},
                    {name: "amount", width: 100, align: 'right'},
                    { name: "amountcalculate", width: 60,
                        formatter: function (cellvalue, options, rowObject)
                        {
                            var rq = parseFloat(rowObject[2] );
                            var up = parseFloat(rowObject[3] );
                            return parseFloat(rq * up).toFixed(2);
                        }
                    }
                ],
                height: "100%",
                rowNum: -1,
                sortname: "name",
                footerrow : true,
                idPrefix: "s_" + rowid + "_"
            });
            debugger
            var $grid = $("#" + subgridTableId);
            var colSum = $grid.jqGrid('getCol', 'amountcalculate', false, 'sum');
            alert(colSum);
            $grid.jqGrid('footerData', 'set', { 'amountcalculate': parseFloat(colSum)});
        },

Please include in all your questions the information about the version of jqGrid, which you use (can use) and the fork of jqGrid ( free jqGrid , commercial Guriddo jqGrid JS or an old jqGrid in version <=4.7). The solution can have depend on the information.

I suppose that the origin of your problem is the usage of custom formatter without specifying the corresponding unformatter function. See the documentation .

In general, it's better to replace custom formatter to jsonmap function, which return the calculated value based on the value of tow other properties. It allows for example to combine the jsonmap function with another formatter, for example with formatter: "currency" , formatter: "integer" and so on.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM