To format a column's display text, set a serialisable format spec on the column. The underlying
value stays a number or date, so sort, filter, and quick-search keep operating on the real value
— only the displayed text changes.
(AG Grid normally formats with a valueFormatter function, but functions can't cross from Lua
into JSON — see the no-functions limit. The format
spec is the serialisable alternative.)
columnDefs = {
{ field = 'length', headerName = 'Length',
format = { style = 'number', useGrouping = true, decimals = 0, suffix = ' m' } },
{ field = 'released', headerName = 'Released',
format = { style = 'date', dateStyle = 'medium' } },
}
-- 1234567 shows as "1,234,567 m" and still sorts numerically| Key | Default | Meaning |
|---|---|---|
useGrouping |
true |
Thousands separators. |
decimals |
— | Fixed number of fraction digits. |
prefix |
— | Literal text before the number. |
suffix |
— | Literal text after the number. |
locale |
viewer's | Locale for grouping/decimal symbols. |
| Key | Meaning |
|---|---|
dateStyle |
'short', 'medium', 'long', or 'full'. |
options |
A full Intl.DateTimeFormat options table. Use instead of dateStyle for finer control. |
locale |
Locale for date wording. Defaults to the viewer's. |
Dates must be ISO-8601 (e.g. 2024-03-09); any other string passes through unchanged.
- Omit
localeto follow the viewer's own locale for grouping and date wording. A fixedprefix/suffixalways stays literal. - Non-numeric or empty values pass through unchanged.
formatbehaves identically on inline grids and on backend source grids.- A Semantic MediaWiki Quantity column already arrives formatted with its unit (e.g.
"27 kg"), soformatis a no-op there. It only takes effect where the source value is a bare number.
- Authoring grids — the inline
gridOptionsmodel - Rich cells — links, thumbnails, and link lists
- Backend source grids — where
formatalso applies