Handsontable Renderer Development
Signature
Renderers are pure functions, no class or state:
function myRenderer(hotInstance, TD, row, col, prop, value, cellProperties) {
baseRenderer.apply(this, arguments);
// Modify TD element here
}
Call baseRenderer first: it applies the readonly and invalid CSS classes, ARIA attributes, and other standard cell setup.
Rules
- Renderers only modify the TD's DOM content and attributes; state, event listeners, and data mutation belong elsewhere (interactivity goes in an editor or plugin).
- Set cell text with
fastInnerText(TD, value)fromsrc/helpers/dom/element.ts(XSS-safe). - Escape all user-provided content before any
innerHTML. - Append or clear through
getCellContentRoot(TD)when managing the cell's children (empty(...),appendChild(...),insertBefore(x, root.firstChild)). A row at an exact height keeps content in adiv.htCellClipwrapper; the helper returns it when present and the cell otherwise. Writing straight intoTDrebuilds the wrapper every draw, and a node left outside it grows the row back.fastInnerText/fastInnerHTMLdo this on their own. Models:checkboxRenderer,autocompleteRenderer,multiSelectRenderer. - If the renderer changes the cell's role or state, update ARIA attributes through
src/helpers/a11y.ts. A control drawn in a cell (a checkbox, a button, a link) needs an accessible name and a keyboard path (handsontable-a11yskill). - Handle
nullandundefinedvalues.
Files
src/renderers/{rendererName}/
{rendererName}.ts # Renderer function
index.ts # Re-exports
Registry: src/renderers/registry.ts.
import { registerRenderer } from '../../renderers/registry';
registerRenderer('myRenderer', myRenderer);
A new built-in renderer also needs its entry in src/renderers/features.json (renderer:<name_in_snake_case>, licensing: "none"; copy a neighbor), and a cell type that uses it lists it in its requires.allOf. The unit suite fails until both exist. Run npm run generate:feature-manifest --prefix handsontable and commit what it writes. Rules: src/featureManifest/AGENTS.md.
Reference implementations
src/renderers/baseRenderer/baseRenderer.tssrc/renderers/textRenderer/textRenderer.ts- simplest, good template.src/renderers/htmlRenderer/htmlRenderer.ts- raw HTML.src/renderers/numericRenderer/numericRenderer.ts- numeral.js formatting.
Performance
Renderers run for every viewport cell on every render cycle (fast and slow).
- Keep logic minimal; read layout properties (
getBoundingClientRect,offsetWidth) outside the renderer to avoid layout thrashing. - Keep allocations and string concatenation out of the hot path.
- Cache a slow derived value (chart markup, a parsed document) by the data record or cell coordinates. The engine reuses a fixed set of
TDelements and rewrites them on scroll, so aTD-keyed cache (WeakMapor a property on it) misses almost every call (issue #13446). Two traps:getSourceDataAtRow()returns a copy on every call, so it cannot be aWeakMapkey; read the record from your own data array bytoPhysicalRow(row)(the cellvalueIS passed by reference).afterRenderdoes not fire for scroll draws; count or refresh per-draw state inafterViewRender. Worked example:docs/content/recipes/performance/expensive-cell-renderer/.