最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

php - jqGrid setCell calculated value - Stack Overflow

programmeradmin1浏览0评论

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

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.

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

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.

Share Improve this question asked Mar 11, 2012 at 13:41 haiderchaiderc 431 gold badge1 silver badge5 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 4

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.

发布评论

评论列表(0)

  1. 暂无评论