Category / Section
How to calculate column values based on other columns
1 min read
The column values can be calculated based on other column values by performing the calculation in the grid’s queryCellInfo event. This event will be triggered before a cell element is appended to the grid and the current row data will be returned in the event arguments. The required column value can thus be calculated using the current cell value.
This is explained in the following code snippet in which a column(Total) cell value is calculated and set to its cell element based on two other columns(Quantity, Freight) cell values(of the same row) in the queryCellInfo event handler.
<script> // Grid’s queryCellInfo event handler queryCellInfo(args) { if (args.column.field === 'Total') { // Column(‘Total’) cell value is calculated and assigned to its cell element args.cell.innerText = Number(args.data.Quantity * args.data.Freight).toFixed(2); } } </script>
Output
You can find the samples here: