Separate calculation and display
Calculate values with valueGetter and create display text with valueFormatter.
Options
Changes below update the Grid and code immediately.
Initially ORD-0001 has quantity 10, unit price 120, and total 1,200. The total is calculated, not entered separately.
View code
Sample data included in the code · 6 rows
Usage guide
#Use this to calculate totals from quantity and price while showing readable numbers such as 1,200. Manage calculated values separately from display text.
Try it yourself
- Read the first order
Initially ORD-0001 has quantity 10, unit price 120, and total 1,200. The total is calculated, not entered separately.
- Edit the quantity
Double-click the first order's quantity, change it to 25, and press Enter.
- Compare the calculation
Check that the total becomes 3,000. Further quantity edits recalculate the total with the same formula.
The total is quantity × unit price, displayed with thousands separators. The total cell is not directly editable.
Numeric sorting and aggregation need actual numbers. Add commas and currency symbols during formatting, not to the calculation result.
Useful terms
- valueGetter
- A function calculating a new value from row values.
- valueFormatter
- A function converting a calculated value into display text.
Key API examples
Application code that references the registered Grid element as grid.
grid.columnDefs = [{field:'total',headerName:'Total',
valueGetter: ({data}) => data.quantity * data.price,
valueFormatter: ({value}) => Number(value).toLocaleString('en-US')
}];API reference
#ColumnDef2
| ColumnDef | Type / Required | Description |
|---|---|---|
GridCallback<[ValueGetterParams<TData, TValue, TContext>], TValue> | stringOptional | Computed value hook. Function callbacks receive value-getter params; string expressions are evaluated by the grid expression parser. | |
GridCallback<[ValueFormatterParams<TData, TValue, TContext>], string> | stringOptional | Converts a resolved cell value into display text. Accepts a function or a template string such as `{{value | round:2}}`. |
Explore each feature
Learn when to use each feature and how to configure it. Each guide identifies live examples and features you connect in your app.