jqGrid setCell calculated value

后端 未结 1 1946
萌比男神i
萌比男神i 2021-01-01 03:56

I need to develop a grid using jqGrid and PHP what has 4 columns: Product, Quantity, Price and Amount. Th

1条回答
  •  刺人心
    刺人心 (楼主)
    2021-01-01 04:19

    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 讨论(0)
提交回复
热议问题