添加一个jqgrid列,它是另外两个列的结果 [英] adding a jqgrid column that is a result of two other columns

查看:205
本文介绍了添加一个jqgrid列,它是另外两个列的结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想对jqGrid表的列值求和.我的jqGrid "SL", "Item", "Quantity", "Rate","Amount"中有四列,其中AmountQuantity*Rate的结果,此乘法不是查询检索到的数据,而是在内部完成的javascript代码.现在我想对金额列求和.总和正确显示.我已经用警报检查了它,但是当我尝试在页脚行$grid.jqGrid('footerData', 'set', { 'amountcalculate': parseFloat(colSum)});上设置它时却显示了NAN.为什么不是我之前使用过页脚行并进行了求和.它工作得非常好.当我尝试添加由另外两列组成的列值时,它不起作用. 这是我的代码

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)});
        },

推荐答案

请在所有问题中包括有关您使用(可以使用)的jqGrid版本和jqGrid分支的信息 (免费jqGrid ,商业

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.

通常,最好将自定义格式化程序替换为jsonmap函数,该函数将基于其他两个属性的值返回计算出的值.例如,它允许将jsonmap函数与另一个格式化程序(例如,与formatter: "currency"formatter: "integer"等)组合.

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.

这篇关于添加一个jqgrid列,它是另外两个列的结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆