Estimated jqGrid setCell

I need to develop a grid using jqGrid and PHP, which has 4 columns: Product , Quantity , Price and Sum . 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 tried the following:

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

Please note that calculateTotal () can correctly calculate the total number of the Quantity column without any errors and can be clearly seen on the footer of the grid.

+4
source share
1 answer

I suppose you are using cell editing . In the case where the afterSaveCell callback is really good for updating the calculated column amount based on the current values ​​from the quantity and price columns. The corresponding code might be something like 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 demonstration does almost the same thing, but calculates the "total" as the sum of the "amount" and "tax". For the test, you must change the value from the column "amount" or "tax" and make sure that "total" will be recalculated.

+4
source

Source: https://habr.com/ru/post/1400839/


All Articles