Skip to content

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.

ts
const columns = [
  { id: 'site', cellRenderer: 'link' },
  {
    id: 'status',
    cellRenderer: 'badge',
    cellRendererParams: { map: { paid: { label: 'Paid', tone: 'success' } } },
  },
  { id: 'done', cellRenderer: 'progress', cellRendererParams: { max: 100 } },
];
KeyDrawsMain options
buttonA button in the cell (<button>)onClick (required), label, disabled, visible, ariaLabel
linkA link (<a>)href, newWindow, baseUrl, onClick
badgeA chip-shaped badgemap, tone
progressA progress barmin, max, ranges, showText, height, gap, labelPosition, scale, label, precision, className
progressRingA circular progress ring (number in the middle)min, max, size, thickness, showLabel, decimals, animate
bulletActual-value bar + target tick (+ bands)target (required), min, max, ranges, height, labelPosition, format
htmlSanitized rich text (bold, links, lists)allowTags, maxLength
ratingStars (read-only)max, shape, half
avatarA round photo or initials, plus a nameimage, name, showText
tagsA list of tag chipsmax, separator
imageAn image in the cell (<img>)src, map, width, height, fit, shape, alt, fallback, onClick
iconA text, emoji or SVG iconicon, map, size, position, tone, label, onClick
sparklineA line sparkline (<svg>)values, curve, area, marks, tone, height, width (Sparklines)
sparkbarsA bar sparklinevalues, gap, negativeTone, highlight, tone (Sparklines)
sparkwinlossA win/loss sparklinevalues, when, winTone, lossTone (Sparklines)
switchA switch you can press (role="switch")checkedValue, uncheckedValue, label, size, disabled, visible, canToggle
checkboxA display-only checkbox; with parameters a control you can press (core bundle)checkedValue, uncheckedValue, label, size, shape, disabled, visible, canToggle

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).

Live demo — drawn by the real renderer

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.

ts
{ 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.

ts
{ 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),
} }
OptionValueEffect
onClickfunction (required)Argument { row, rowKey, columnId, value, event }; missing is an invalid-option
labeltext or functionDefault is the cell text (the formatValue result)
disabledboolean or functiontrue sets the disabled attribute and the button cannot be pressed
visibleboolean or functionfalse leaves the cell empty (no button)
ariaLabeltext or functionThe 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.

ts
{ id: 'active', editable: true, cellRenderer: 'switch',
  cellRendererParams: { checkedValue: 'Y', uncheckedValue: 'N', label: 'Active',
    canToggle: ({ row, next }) => !(next === 'N' && row.locked) } }
OptionValueEffect
checkedValuestring, number, booleanStored value for the checked state. Default true
uncheckedValuestring, number, booleanStored value for the unchecked state. Default false; equal to checkedValue is an error
labeltextText 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, visibleboolean or functionDisable or hide. A function receives { row, rowKey, columnId, value }
canTogglefunctionReturning 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 and editCommitted all work as for any edit. The column parse is not applied to these values (do not combine parse with string value mapping).
  • When the column is not editable (editable false, locked), the row condition is false, or disabled is 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: checkbox has role="checkbox", switch has role="switch", and both use aria-checked.
  • Filter, sort, export and paste all work on the stored value ('Y'/'N'). Use format to show other text. The built-in boolean filter (filter: { type: 'boolean' }) only knows true and false, so using it on a column with changed values is an invalid-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.

Live demo — drawn by the real renderer

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.

OptionValueMeaning
height2–40 (px)Bar thickness. Default is the theme value (8px)
gap0–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%
precision0–6Decimals for label: 'percent'. Default 0
classNamespace-separated classesAdded to the bar track
ranges[].classNameclassEach band needs tone, className or both

Progress bar options example

The rating rounds the value and clamps it between 0 and max.

OptionValuesWhat it does
maxinteger 1 to 10 (default 5)Number of stars
shape'glyph', 'soft'Glyph stars (★☆) or round-cornered SVG stars. Omitted follows the grid's iconStyle
halftrue, 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.

Live demo — drawn by the real renderer

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).

ts
{ id: 'done', cellRenderer: 'progressRing', cellRendererParams: { max: 100, size: 28 } }
OptionValueMeaning
min, maxnumberValue range. Default 0 and 100
size16–64 (px)Ring diameter. Default 26. The size stays fixed when the value changes
thickness1–12 (px)Ring thickness. Default 3
showLabeltrue (default) · falseShow the number in the middle
decimals0–6Decimal places of the number. Default 0
animatetrue · 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" with aria-valuemin, aria-valuemax, aria-valuenow, aria-valuetext (for example 40%) and the column title as its name. The SVG is aria-hidden, so the number in the middle is not read twice.
  • The number follows the locale rules. A long number shrinks to fit inside the ring.
  • Sorting, copy and export use the cell value. The colors use currentColor and theme tokens, so the dark theme and forced-colors mode follow.

Progress ring example

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.

ts
{ id: 'sales', cellRenderer: 'bullet',
  cellRendererParams: { target: 'goal', ranges: [{ upTo: 50, tone: 'danger' }, { upTo: 100, tone: 'success' }] } }
OptionValueMeaning
targetstring (row field name) or function (required)The target value. A function receives the row. A non-number draws no tick
min, maxnumberScale 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
height4–40 (px)Track thickness. Default 16
labelPosition'end' (default) · 'inside' · 'none'Where the label goes
formatfunction (actual, target) => stringLabel 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 bulletLabel and bulletLabelNoTarget).
  • Sorting, copy and export use the cell value.
  • The bar and tick use --mxg-fg and 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.

ts
{ id: 'note', cellRenderer: 'html', cellRendererParams: { allowTags: ['b', 'i', 'a'] } }
OptionValueMeaning
allowTagsarray of stringsNarrows the default tags. Adding a tag that is not in the list is invalid-option
maxLength1–100000Source characters to read. Default 2000. The rest is dropped
  • Default tags: b i u s em strong small sup sub mark code br span a ul ol li p.
  • Attributes: only href, title and target on a stay. class, style, id, data-* and event attributes are all removed. target keeps only _blank, and links always get rel="noopener noreferrer".
  • Link addresses: only http, https, mailto and relative addresses stay. javascript:, data: and vbscript: are removed and the link keeps only its text.
  • Removed tags: script, style, iframe, object, embed, svg, math, template and 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 formatValue you give wins).
  • Row height does not grow. For several lines combine the column's wrap with rowHeight: '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.

HTML example, Links example

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.

Live demo — drawn by the real renderer

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.

ts
{ 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)ValueDefaultEffect
srcstring or functionthe cell valueThe URL; a function gets { row, rowKey, columnId, value }
map{ value: URL }noneURL for a value; looked at before src
heightinteger (px, 1-400) or 'row'20'row' is row height minus 4px; a number is also capped at row height minus 4px
widthnumber (px)same as heightWidth; 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
altstring or functionemptyAlternative text; empty makes it decorative
fallback'hide' · 'text''hide'When the URL is missing, refused or fails to load; text shows the cell text
onClickfunctionnoneIf set, the image becomes a <button> and the function gets { ..., event }
Option (icon)ValueDefaultEffect
iconstring or functionnoneThe icon: text or emoji (up to 4 characters) or an <svg> string
map{ value: icon }noneIcon for a value; looked at before icon
size8-6416Icon 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 colorColor (a token, so dark mode follows)
labelstring or functionthe cell textAccessible name; with only it names the role="img"
onClickfunctionnoneIf set, the icon becomes a button
  • Image URLs accept http, https and PNG, JPEG, GIF or WebP data: URLs only. javascript:, SVG data: 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 icons option (svg, g, path, circle, ellipse, rect, line, polyline, polygon, title and shape attributes). Markup with scripts, event attributes or external references is refused, reported once through the error event (callback-error), and the cell stays empty.
  • With onClick the 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, and cellClicked arrives as for any other cell.
  • If a function option throws, the error is reported through the error event (callback-error) and the default is used (no URL, empty alt, the cell text).

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%".

Live demo — drawn by the real renderer

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:

ts
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 ​

SituationChoose
The six shapes and their options are enoughA built-in renderer
A rating, button or switch that changes the value on clickWrite an adapter
Other markup, such as emoji flags, a sparkline or a color swatchWrite an adapter
You want to draw with a framework componentreactCell, 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.