jqGrid setCell计算值 [英] jqGrid setCell calculated value

查看:99
本文介绍了jqGrid setCell计算值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要使用jqGrid和PHP开发一个有4列的网格:产品数量价格金额即可。从数据库中检索产品名称。如果用户编辑数量和价格列,则应通过将数量价格列相乘来自动更改金额单元格。我尝试过如下:

I need to develop a grid using jqGrid and PHP what has 4 columns: Product, Quantity, Price and Amount. The product name is retrieved from the database. If the user edits the Quantity and Price columns, the amount cell should be changed automatically by multiplying the Quantity and Price columns. I've tried as follows:

var grid = $("#reportTable");

........

afterSaveCell: function (rowid, name, val, iRow, iCol) {
  grid.jqGrid("setCell", rowid, "amount", val, "");
  calculateTotal();
}

请注意 calculateTotal()可以计算以及数量列的完整摘要没有任何错误,并且可以完美地显示在网格的页脚上。

Please note that the calculateTotal() can calculate well the grand summary of the Quantity column without any error, and can show on the footer of the grid perfectly.

推荐答案

我想您使用单元格编辑。如果 afterSaveCell 回调真是个好地方根据列数量价格 c code>。相应的代码可以是以下

I suppose that you use cell editing. In the case the afterSaveCell callback is really good place to update the calculated column amount based on the current values from the columns quantity and price. The corresponding code could be about the following

afterSaveCell: function (rowid, cellname, value) {
    var quantity, price, $this;
    if (cellname === 'quantity' || cellname === 'price') {
        $this = $(this);
        quantity = parseFloat($this.jqGrid("getCell", rowid, 'quantity'));
        price = parseFloat($this.jqGrid("getCell", rowid, 'price'));
        $this.jqGrid("setCell", rowid, 'amount', quantity * price);
    }
}

演示几乎相同,但计算'总数'为'金额'和'税'的总和。对于测试,您应该修改金额或税列中的值,并确认将重新计算总计。

The demo do almost the same, but calculate 'total' as the sum of 'amount' and 'tax'. For the test you should modify the value from 'amount' or 'tax' column and verify that 'total' will be recalculated.

这篇关于jqGrid setCell计算值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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