Skip to content

Custom UI functions

A Genie app is generated from XML, but the host project can add its own code in a few fixed places. All of them go in the handlers block of createGenieApp:

Handler What it adds Used from XML by
expressionFunctions Functions for client-side expressions StyleClassesExpression, and field Required / Disabled / Hidden / Value rules
renderers React components that draw a value Render="key" on a <Column> or a view field
cellClass Extra CSS classes per table cell nothing — applies to every grid
classNames Class names for fixed slots nothing

You can’t add a new callback function (FunctionName). That registry is closed on purpose, because callback names come from SQL data.

Keep them in their own module so they’re easy to find and test:

src/genie/handlers.tsx
import type { GenieHandlers, GenieRenderContext } from "@genie/genie-engine-ui";
/** Formats a number as money in the user's locale. Used as Money(Total) in expressions. */
function Money(value: unknown): string {
return new Intl.NumberFormat(undefined, { style: "currency", currency: "PKR" }).format(Number(value) || 0);
}
/** True when a date is in the past. Used as IsPast(DueDate) in expressions. */
function IsPast(value: unknown): boolean {
const t = Date.parse(String(value ?? ""));
return !Number.isNaN(t) && t < Date.now();
}
/** Star rating cell for Render="rating". */
function RatingCell({ value }: GenieRenderContext) {
const stars = Math.max(0, Math.min(5, Number(value) || 0));
return <span aria-label={`${stars} of 5 stars`}>{"★".repeat(stars)}{"☆".repeat(5 - stars)}</span>;
}
// Module scope on purpose: createGenieApp captures its config once, and a renderer map rebuilt on every
// render would only add churn.
export const HANDLERS: GenieHandlers = {
expressionFunctions: { Money, IsPast },
renderers: {
rating: (ctx) => <RatingCell {...ctx} />,
},
cellClass: (column, row) =>
column.Name === "DueDate" && IsPast(row.Cells.DueDate) ? "gx-danger" : null,
};
src/main.tsx
import { createGenieApp } from "@genie/genie-engine-ui";
import { HANDLERS } from "./genie/handlers";
const GenieApp = createGenieApp({
apiBase: "/api/v1/genie",
handlers: HANDLERS,
});
<Columns>
<Column Name="Total" StyleClassesExpression="If(Total > 100000, 'gx-warning', '')" />
<Column Name="DueDate" StyleClassesExpression="If(IsPast(DueDate), 'gx-danger', '')" />
<Column Name="Rating" Render="rating" Export="false" />
</Columns>
<!-- A form field rule using a host function -->
<EditorField Name="Reason" Required="IsPast(DueDate)" />
  • Arguments are whatever the expression passes: field or column values, literals, or the results of other functions. Convert them yourself (Number(x), String(x)). A value can be null or "".
  • They run in the browser only. Field rules are also enforced on the server on submit, through a C# copy of the built-in functions. A host function is unknown there, and a rule that calls one evaluates to false on the server, so a Required rule using it is shown in the browser but not enforced on submit. Use host functions for display and convenience. Keep a rule that must hold in built-ins or in the submit SQL.
  • Names merge over the built-ins (If/IIF, sumLines, …). A host function with the same name replaces the built-in everywhere, so pick distinct names.
  • Keep them pure and fast. They run on every render of every cell or field that uses them. No network calls and no side effects.

See Expression engine for the expression syntax.

A renderer receives { value, classes, row?, column?, field? } and returns a React node:

  • value: the display string. A column Expression runs first and replaces it, so a renderer column should not have one.
  • classes: the resolved StyleClasses + StyleClassesExpression, so you can reuse the colour.
  • row: the whole grid row (row.Cells.<Column>) for a table cell, including hidden columns. This is how a renderer reads more than one value.
  • column / field: the column or view field being drawn.

Rules:

  • Return nodes, never HTML. Pass values as text children so React escapes them. Never use dangerouslySetInnerHTML with data.
  • Never throw. A renderer runs inside the table’s render, so an exception takes down the whole grid. If the value doesn’t parse, show it as plain text.
  • A host key wins over the built-ins (badge, tags, bullets, progress). An unregistered key falls back to plain text, so a cell showing raw JSON usually means the registration is missing.
  • Set Export="false" on a column whose value is a JSON payload for its renderer, or exports will contain the raw JSON.

A cell that needs data from several columns can read the hidden ones from row:

/** Links to the record a row names, when the target view changes per row. */
function RecordLinkCell({ value, row }: GenieRenderContext) {
const view = String(row?.Cells.DocumentView ?? "");
const id = String(row?.Cells.EntityId ?? "");
if (!view || !id) return <>{value}</>;
return <a href={`/object/${encodeURIComponent(view)}?id=${encodeURIComponent(id)}`}>{value}</a>;
}
<Column Name="DocumentView" Hide="true" Export="false" />
<Column Name="EntityId" Hide="true" Export="false" />
<Column Name="Document" Render="record-link" />

A form field (<EditorFields>) whose Render names a host renderer is drawn by it, read-only, in place of its editor control, with the field’s label above. Use it to put a link or a computed panel inside an editable form, for example a “View activity” link on an approval form:

<Text Name="ActivityLink" Label="Activity" Disabled="true" Render="activity-link" />

The renderer receives the field’s value and field. Built-in renderers (badge, tags, bullets, progress) apply to grids and read-only views only, and never replace a form’s editor control. A rendered field is display only: its value is still posted with the form, but the user cannot change it.

A renderer can also draw a whole sub-view tab. See Custom sub-view panels.

cellClass(column, row) returns extra classes for a cell, added after the column’s own classes. Use it for a rule that applies to many views at once. A rule for one column belongs in that column’s StyleClassesExpression.

classNames.attachmentCell adds a class to the wrapper around attachment chips in tables and views.