Built-in cell renderers
Common cells such as links, status badges and progress bars need no code. Put a key in the column's cellRenderer, and any options in cellRendererParams.
const columns = [
{ id: 'site', cellRenderer: 'link' },
{
id: 'status',
cellRenderer: 'badge',
cellRendererParams: { map: { paid: { label: 'Paid', tone: 'success' } } },
},
{ id: 'done', cellRenderer: 'progress', cellRendererParams: { max: 100 } },
];| Key | Draws | Main options |
|---|---|---|
button | A button in the cell (<button>) | onClick (required), label, disabled, visible, ariaLabel |
link | A link (<a>) | href, newWindow, baseUrl, onClick |
badge | A chip-shaped badge | map, tone |
progress | A progress bar | min, max, ranges, showText, height, gap, labelPosition, scale, label, precision, className |
progressRing | A circular progress ring (number in the middle) | min, max, size, thickness, showLabel, decimals, animate |
bullet | Actual-value bar + target tick (+ bands) | target (required), min, max, ranges, height, labelPosition, format |
html | Sanitized rich text (bold, links, lists) | allowTags, maxLength |
rating | Stars (read-only) | max, shape, half |
avatar | A round photo or initials, plus a name | image, name, showText |
tags | A list of tag chips | max, separator |
image | An image in the cell (<img>) | src, map, width, height, fit, shape, alt, fallback, onClick |
icon | A text, emoji or SVG icon | icon, map, size, position, tone, label, onClick |
sparkline | A line sparkline (<svg>) | values, curve, area, marks, tone, height, width (Sparklines) |
sparkbars | A bar sparkline | values, gap, negativeTone, highlight, tone (Sparklines) |
sparkwinloss | A win/loss sparkline | values, when, winTone, lossTone (Sparklines) |
switch | A switch you can press (role="switch") | checkedValue, uncheckedValue, label, size, disabled, visible, canToggle |
checkbox | A display-only checkbox; with parameters a control you can press (core bundle) | checkedValue, uncheckedValue, label, size, shape, disabled, visible, canToggle |
Links
When the value is the address, no options are needed. For email and phone, put {value} in an href string. {value} and {row.field} are filled in URL-encoded, and a function can build the address from the row or return undefined to skip the link.
Only http, https, mailto and tel are allowed. javascript:, data: and relative paths do not become links; they are drawn as plain text. A link that opens a new window gets rel="noopener noreferrer" (newWindow: false keeps the same tab).
Shared address prefix and click handling
Give baseUrl an absolute http(s) address and the final address is baseUrl + (the href result, or the cell text when there is none). The cell text is URL-encoded when appended, and the result goes through the same allow-list as above. A baseUrl that is not an absolute http(s) address fails with invalid-option.
In an href string, {raw:value} and {raw:row.field} are filled in without encoding. Use them when the value is already a complete address or must keep its /. If the result fails the allow-list (javascript: and so on), the cell is plain text with no link, as before.
onClick runs when the link is clicked or opened with Enter or Space, before navigation. It receives { value, text, row, rowKey, columnId, href, event }, and event.preventDefault() cancels navigation. An exception is reported as an error event (callback-error) and the grid keeps rendering. It does not run on a cell whose address was blocked and shows plain text.
{ id: 'ticket', cellRenderer: 'link', cellRendererParams: { baseUrl: 'https://tracker.example.com/issues/' } }
{ id: 'doc', cellRenderer: 'link', cellRendererParams: { href: '{raw:row.path}' } }
{ id: 'site', cellRenderer: 'link', cellRendererParams: { onClick: (c) => { if (!ok(c.href)) c.event.preventDefault(); } } }See also building the address from the row.
Buttons
cellRenderer: 'button' draws <button type="button" class="mxg-btn"> in the cell. A click calls onClick only. It does not start an edit or change the selection, and cellClicked arrives like for any other cell.
{ id: 'state', cellRenderer: 'button', cellRendererParams: {
label: (ctx) => (ctx.row.state === 'open' ? 'Process' : 'Done'),
disabled: (ctx) => ctx.row.state === 'done',
visible: (ctx) => ctx.row.canAct,
onClick: ({ row, rowKey, columnId, value, event }) => process(row),
} }| Option | Value | Effect |
|---|---|---|
onClick | function (required) | Argument { row, rowKey, columnId, value, event }; missing is an invalid-option |
label | text or function | Default is the cell text (the formatValue result) |
disabled | boolean or function | true sets the disabled attribute and the button cannot be pressed |
visible | boolean or function | false leaves the cell empty (no button) |
ariaLabel | text or function | The accessible name; default is the visible text |
Function options receive { row, rowKey, columnId, value }. If label, disabled, visible or onClick throws, the grid keeps running and reports it through the error event (callback-error). A throwing label falls back to the cell text, disabled to pressable and visible to shown. With the keyboard, focus the cell and press Enter or Space to press its button right away (there is no step into the cell). This applies only when the button is the one element the keyboard can reach in the cell; with several elements, Enter steps into the first one.
Checkbox and switch
Give cellRenderer: 'checkbox' a cellRendererParams, or use 'switch', and the cell becomes a control you can press. A checkbox without parameters is the display-only checkbox of 1.3.4.
{ id: 'active', editable: true, cellRenderer: 'switch',
cellRendererParams: { checkedValue: 'Y', uncheckedValue: 'N', label: 'Active',
canToggle: ({ row, next }) => !(next === 'N' && row.locked) } }| Option | Value | Effect |
|---|---|---|
checkedValue | string, number, boolean | Stored value for the checked state. Default true |
uncheckedValue | string, number, boolean | Stored value for the unchecked state. Default false; equal to checkedValue is an error |
label | text | Text next to the control and its accessible name; default is the column title |
size | 'sm' · 'md' · 'lg' | Control size. Default 'md' |
shape | 'square' · 'round' | checkbox only; on switch it is an invalid-option |
disabled, visible | boolean or function | Disable or hide. A function receives { row, rowKey, columnId, value } |
canToggle | function | Returning false keeps the value (no event). The argument also has next |
With the keyboard, focus the cell and press Enter, F2 or Space to change the value. No edit box opens; letter keys and double-click do nothing.
- Checked means
value === checkedValue(strict). Every other value is drawn unchecked, and an object is never checked. - A click, or Space on the focused control, writes the next value through the normal edit commit path. Value transform (
transformEdit), validation, undo (one step), change tracking andeditCommittedall work as for any edit. The columnparseis not applied to these values (do not combineparsewith string value mapping). - When the column is not editable (
editablefalse, locked), the row condition is false, ordisabledis set, the control is drawn disabled (aria-disabled) and cannot be pressed. A press never opens the text editor, and the cell selection only moves focus like a normal click. - Accessibility:
checkboxhasrole="checkbox",switchhasrole="switch", and both usearia-checked. - Filter, sort, export and paste all work on the stored value (
'Y'/'N'). Useformatto show other text. The built-in boolean filter (filter: { type: 'boolean' }) only knowstrueandfalse, so using it on a column with changed values is aninvalid-option. - The selection checkbox column is a separate feature and stays as it is.
Badges and tones
map sets a label and a tone per value. The tones are neutral, info, success, warning and danger. The theme owns the colors, and text contrast is 4.5:1 or better in light and dark. Arbitrary colors are not accepted. The label text is always there, so meaning never depends on color alone.
tone can also be a function of the value and the row (pick the tone from a number).
Progress and rating
The progress bar carries role="progressbar" and aria-valuemin/max/now. A value outside the range is clamped, and a value that is not a number leaves the bar empty. ranges uses the tone of the first band whose upTo is at or above the percentage.
Progress bar look options
All are optional. With none set, the bar is drawn exactly as in 1.3.2.
| Option | Value | Meaning |
|---|---|---|
height | 2–40 (px) | Bar thickness. Default is the theme value (8px) |
gap | 0–40 (px) | Space between bar and label. Default 6 |
labelPosition | 'end' (default), 'start', 'inside', 'none' | Label position. 'inside' centers it over the bar; 'none' equals showText: false |
scale | 'percent' (default), 'ratio' | 'ratio' reads values 0–1 as 0–100% (min/max default 0/1) |
label | 'text' (default), 'percent' | 'percent' makes the renderer build text such as 33% |
precision | 0–6 | Decimals for label: 'percent'. Default 0 |
className | space-separated classes | Added to the bar track |
ranges[].className | class | Each band needs tone, className or both |
The rating rounds the value and clamps it between 0 and max.
| Option | Values | What it does |
|---|---|---|
max | integer 1 to 10 (default 5) | Number of stars |
shape | 'glyph', 'soft' | Glyph stars (★☆) or round-cornered SVG stars. Omitted follows the grid's iconStyle |
half | true, false (default) | With true values round to 0.5 and half stars are drawn. Screen readers read the decimal, 3.5 |
It is read-only, and screen readers hear 4 / 5. For a rating that changes on click, use the custom renderer example.
Progress ring
Since 1.8.0
progressRing is available since 1.8.0.
progressRing draws the cell value as a circular ring with the percentage in the middle. It takes less room than a bar in a narrow column. It needs the optional renderers bundle (like bullet).
{ id: 'done', cellRenderer: 'progressRing', cellRendererParams: { max: 100, size: 28 } }| Option | Value | Meaning |
|---|---|---|
min, max | number | Value range. Default 0 and 100 |
size | 16–64 (px) | Ring diameter. Default 26. The size stays fixed when the value changes |
thickness | 1–12 (px) | Ring thickness. Default 3 |
showLabel | true (default) · false | Show the number in the middle |
decimals | 0–6 | Decimal places of the number. Default 0 |
animate | true · false (default) | Fill smoothly when the value changes (stops under reduced motion) |
- The value is clamped to
min–max. A non-number draws an empty ring with no value attributes. - The outer element is
role="progressbar"witharia-valuemin,aria-valuemax,aria-valuenow,aria-valuetext(for example40%) and the column title as its name. The SVG isaria-hidden, so the number in the middle is not read twice. - The number follows the
localerules. A long number shrinks to fit inside the ring. - Sorting, copy and export use the cell value. The colors use
currentColorand theme tokens, so the dark theme and forced-colors mode follow.
Bullet
bullet draws the cell value as a bar (actual) and another value of the same row as a vertical tick (target). You see "actual versus target" at a glance without writing an adapter. It needs the optional renderers bundle.
{ id: 'sales', cellRenderer: 'bullet',
cellRendererParams: { target: 'goal', ranges: [{ upTo: 50, tone: 'danger' }, { upTo: 100, tone: 'success' }] } }| Option | Value | Meaning |
|---|---|---|
target | string (row field name) or function (required) | The target value. A function receives the row. A non-number draws no tick |
min, max | number | Scale range. Default 0 and the largest of actual, target and the last range |
ranges | [{ upTo, tone }] | Paints the track in light tones up to upTo. tone is required |
height | 4–40 (px) | Track thickness. Default 16 |
labelPosition | 'end' (default) · 'inside' · 'none' | Where the label goes |
format | function (actual, target) => string | Label text. Default "actual / target" |
- A non-numeric cell value is an empty cell. Values are clamped to the scale.
- Screen readers read "Actual 82, target 100" (locale texts
bulletLabelandbulletLabelNoTarget). - Sorting, copy and export use the cell value.
- The bar and tick use
--mxg-fgand the bands use tone tokens, so the dark theme and forced-colors mode follow.
Bullet example, Band colors and label example
HTML
Cell values go into the DOM as plain text (textContent) by default. Use html only when the value carries markup such as bold text, links or lists. The value (a string) is run through an allowlist sanitizer and only the result is drawn. It needs the optional renderers bundle.
{ id: 'note', cellRenderer: 'html', cellRendererParams: { allowTags: ['b', 'i', 'a'] } }| Option | Value | Meaning |
|---|---|---|
allowTags | array of strings | Narrows the default tags. Adding a tag that is not in the list is invalid-option |
maxLength | 1–100000 | Source characters to read. Default 2000. The rest is dropped |
- Default tags:
biusemstrongsmallsupsubmarkcodebrspanaulollip. - Attributes: only
href,titleandtargetonastay.class,style,id,data-*and event attributes are all removed.targetkeeps only_blank, and links always getrel="noopener noreferrer". - Link addresses: only
http,https,mailtoand relative addresses stay.javascript:,data:andvbscript:are removed and the link keeps only its text. - Removed tags:
script,style,iframe,object,embed,svg,math,templateand similar are removed together with their content. A tag outside the list loses the tag but keeps its text. - Limits: 8 levels of nesting and 200 nodes. Anything beyond is not drawn.
- On failure: a non-string value or an unreadable string is shown as plain text.
- Text: copy, find, export, sorting and tooltips use the text without tags (a
formatValueyou give wins). - Row height does not grow. For several lines combine the column's
wrapwithrowHeight: 'auto'.
The renderer exists to show values you cannot trust (user input) safely. Still, use it only where you need it and prefer passing values already cleaned on the server. The policy is in Errors and safety.
Avatars and tags
The avatar draws the photo that image points to, and falls back to initials when there is none or it fails to load. Photo addresses can be http(s) or data: URIs for PNG, JPEG, GIF and WebP. SVG data: URIs are refused.
Tags draw an array of strings, or a delimited string, as chips. More than max fold into a +N chip, and hovering it shows the rest.
Images and icons
image draws an image in the cell, and icon draws a text, emoji or SVG icon chosen by the value. Both need the optional renderers bundle.
{ id: 'photo', cellRenderer: 'image', cellRendererParams: { height: 'row', shape: 'round', alt: ({ row }) => row.name } },
{ id: 'state', cellRenderer: 'icon',
cellRendererParams: { map: { ok: '✔', fail: '✘' }, tone: 'success', position: 'before' } }Option (image) | Value | Default | Effect |
|---|---|---|---|
src | string or function | the cell value | The URL; a function gets { row, rowKey, columnId, value } |
map | { value: URL } | none | URL for a value; looked at before src |
height | integer (px, 1-400) or 'row' | 20 | 'row' is row height minus 4px; a number is also capped at row height minus 4px |
width | number (px) | same as height | Width; the width and height attributes are always written so the cell does not shift |
fit | 'contain' · 'cover' | 'contain' | How the image fits the box |
shape | 'square' · 'round' | 'square' | Shape |
alt | string or function | empty | Alternative text; empty makes it decorative |
fallback | 'hide' · 'text' | 'hide' | When the URL is missing, refused or fails to load; text shows the cell text |
onClick | function | none | If set, the image becomes a <button> and the function gets { ..., event } |
Option (icon) | Value | Default | Effect |
|---|---|---|---|
icon | string or function | none | The icon: text or emoji (up to 4 characters) or an <svg> string |
map | { value: icon } | none | Icon for a value; looked at before icon |
size | 8-64 | 16 | Icon size in px |
position | 'only' · 'before' · 'after' | 'only' | only draws the icon alone; the others put it before or after the cell text |
tone | 'info' · 'success' · 'warning' · 'danger' · 'muted' | text color | Color (a token, so dark mode follows) |
label | string or function | the cell text | Accessible name; with only it names the role="img" |
onClick | function | none | If set, the icon becomes a button |
- Image URLs accept
http,httpsand PNG, JPEG, GIF or WebPdata:URLs only.javascript:, SVGdata:and URLs that carry credentials (https://user:pw@host/…) are refused. Private and local hosts are not blocked, so an in-house image server works. Images load lazily and send no referrer. - If no URL or icon matches the value, the cell stays empty. A URL that failed to load is not retried in the same cell.
- SVG icons accept the same allow list as the
iconsoption (svg,g,path,circle,ellipse,rect,line,polyline,polygon,titleand shape attributes). Markup with scripts, event attributes or external references is refused, reported once through theerrorevent (callback-error), and the cell stays empty. - With
onClickthe target is a<button type="button">, so the keyboard (Enter and Space) and the focus ring work as in the browser; it is not a tab stop, so arrow key movement is not blocked. Clicking does not start an edit, andcellClickedarrives as for any other cell. - If a function option throws, the error is reported through the
errorevent (callback-error) and the default is used (no URL, emptyalt, the cell text).
Gallery example: renderer-image
Gallery example: renderer-icon
The value does not change
A renderer changes only how a cell looks. Values go in as text nodes, so a value like <script> or <img onerror> appears as text. Sorting, filtering, copy and CSV export use the value (getValue and formatValue), not the renderer. A progress of 72 sorts as a number, not as the text "72%".
Vertical alignment and density
Anything that is not text is drawn inside a mxg-cell-center box, so it sits at the vertical center. Chips and bars follow the row height when you change density. A link is text, so it needs no box.
Bundles and wrappers
checkbox is in the core bundle. The other eight keys need the renderers feature. The all-in-one bundle (maxgrid) and the React, Vue and Angular wrappers have it on, so a name is enough. In a modular bundle, register it:
import { createGrid } from 'maxgrid/core';
import { renderers } from 'maxgrid/renderers';
createGrid(el, { columns, rows, features: [renderers] });Using 'badge' without it fails with an error that names the feature. For sizes, see Pick the features you need.
In a wrapper you can mix these with component renderers (reactCell, vueCell, angularCell) in the same grid, one column at a time. cellRendererParams works only with a built-in key. If you rebuild the columns array on every render, cells are created again, so keep the same reference with useMemo, computed or similar.
Built-in or your own
| Situation | Choose |
|---|---|
| The six shapes and their options are enough | A built-in renderer |
| A rating, button or switch that changes the value on click | Write an adapter |
| Other markup, such as emoji flags, a sparkline or a color swatch | Write an adapter |
| You want to draw with a framework component | reactCell, vueCell, angularCell |
The built-in badge next to a custom one makes the choice easier.
Errors
If an option function such as href or tone throws, only that cell shows the error state and an error event arrives. The other cells keep drawing. An unknown key or a bad option fails with invalid-option before the grid is created.