Renderer

Register reusable renderers once and use them across Form, Table, filters, editors, and toolbars.

Renderer

The global renderer registry lets an application give a reusable UI behavior a stable name. Form and Table resolve the same registry, so one definition can format a Table cell, edit it, render a Form item, provide a filter control, or create a toolbar item.

Register application renderers from an entry module or a dedicated startup module. Do not register them inside a component’s setup function: remounting that component would repeat a global side effect. Use a slot when the rendering is unique to one component instance.

Register renderers

Use renderer.add(name, definition) for one renderer. Prefer TSX in a dedicated .tsx startup module; switch to the equivalent h() version when the project does not enable JSX. Every stage below explicitly annotates its options, params, and return type, so the available context is visible without relying on editor hover information.

Render syntax
/** @jsxImportSource vue */
import { defineTableRenderer, renderer } from 'sax-design-vue'
import type {
  FormRendererParams,
  RendererOptions,
  TableDefaultRendererParams,
  TableGlobalEditRendererParams,
  TableGlobalFilterRendererParams,
  TableGlobalToolbarRendererParams,
} from 'sax-design-vue'
import type { VNodeChild } from 'vue'

interface User {
  id: number
  name: string
  status: 'active' | 'paused'
}

interface UserQueryForm {
  status?: User['status']
}

interface StatusOption {
  label: string
  value: User['status']
}

const defaultOptions: StatusOption[] = [
  { label: 'Active', value: 'active' },
  { label: 'Paused', value: 'paused' },
]

const renderStatusControl = <Model extends object>(
  options: RendererOptions<Model>,
  params: Pick<FormRendererParams<Model>, 'value' | 'disabled' | 'setValue'>,
): VNodeChild => {
  const choices =
    (options.options as StatusOption[] | undefined) ?? defaultOptions
  return (
    <select
      value={String(params.value ?? '')}
      disabled={params.disabled}
      onChange={(event) =>
        params.setValue((event.target as HTMLSelectElement).value)
      }
    >
      {choices.map((option) => (
        <option value={option.value}>{option.label}</option>
      ))}
    </select>
  )
}

renderer.add(
  '$userStatus',
  defineTableRenderer<User, UserQueryForm>({
    renderDefault: (
      _options: RendererOptions<User>,
      params: TableDefaultRendererParams<User>,
    ): VNodeChild => (
      <span data-status={params.row.status}>{params.value}</span>
    ),

    renderEdit: (
      options: RendererOptions<User>,
      params: TableGlobalEditRendererParams<User>,
    ): VNodeChild => renderStatusControl(options, params),

    renderFormItem: (
      options: RendererOptions<UserQueryForm>,
      params: FormRendererParams<UserQueryForm>,
    ): VNodeChild => renderStatusControl(options, params),

    renderFilter: (
      options: RendererOptions,
      params: TableGlobalFilterRendererParams<User>,
    ): VNodeChild => renderStatusControl(options, params),

    renderToolbar: (
      _options: RendererOptions,
      params: TableGlobalToolbarRendererParams<User, UserQueryForm>,
    ): VNodeChild => (
      <span>
        Selected: {params.source.table.getSelectedRows()[0]?.name ?? 'None'}
      </span>
    ),
  }),
)

Import that module once from the application entry. renderer.mixin() registers several definitions together. The registry also provides get, has, entries, and delete; adding an existing name replaces that global definition.

defineTableRenderer<Row, QueryForm>() carries the business row and query-form types through all five stages. Display and edit receive row and draftRow, Form rendering receives the query model, filtering receives the column, and toolbar rendering receives the fully typed Table and query context through params.source.

// main.ts
import { createApp } from 'vue'
import SaxDesignVue from 'sax-design-vue'
import App from './App.vue'
import './app/renderers'

createApp(App).use(SaxDesignVue).mount('#app')

Use registered renderers

Form references a renderer with itemRender.name. A Table column uses renderer.name for body display and editing, filterRender.name for its filter panel, and toolbarConfig.left or toolbarConfig.right uses itemRender for toolbar content.

import type {
  FormItemConfig,
  TableColumn,
  TableToolbarConfig,
} from 'sax-design-vue'

type ProjectRow = {
  id: number
  status: string
}

const statusOptions = [
  { label: 'Active', value: 'active' },
  { label: 'Paused', value: 'paused' },
]

const formItems: FormItemConfig[] = [
  {
    field: 'status',
    title: 'Status',
    itemRender: { name: '$status', options: statusOptions },
  },
]

const columns: TableColumn<ProjectRow>[] = [
  {
    field: 'status',
    title: 'Status',
    editor: true,
    renderer: { name: '$status', options: statusOptions },
    filterRender: { name: '$status', options: statusOptions },
    filterMethod: ({ value, values }) => value === values[0],
  },
]

const toolbarConfig: TableToolbarConfig = {
  left: [
    {
      itemRender: '$buttons',
      props: { maxVisible: 1, trigger: 'click' },
      options: [
        { code: 'create', text: 'Create' },
        { code: 'delete', text: 'Delete' },
      ],
    },
  ],
  right: [{ itemRender: '$refresh' }, { itemRender: '$columnConfig' }],
}

props and attrs are forwarded to the rendered component. options supplies choices or actions. Handlers in events receive the renderer context first, followed by the component event arguments. An explicit slot or component-local Table renderer keeps precedence over the global entry.

Renderer contract

RendererOptions<Model> is the shared renderer configuration for Form, Table body cells, editors, filters, and toolbars. Model is Row during display and editing, and QueryForm during Form rendering. The old FormItemRenderOptions name remains only as a deprecated compatibility alias.

A definition implements only the methods it needs. All five methods return VNodeChild; their complete signatures are:

interface RendererMethods<Row extends object, QueryForm extends object> {
  renderDefault?: (
    options: RendererOptions<Row>,
    params: TableDefaultRendererParams<Row>,
  ) => VNodeChild
  renderEdit?: (
    options: RendererOptions<Row>,
    params: TableGlobalEditRendererParams<Row>,
  ) => VNodeChild
  renderFormItem?: (
    options: RendererOptions<QueryForm>,
    params: FormRendererParams<QueryForm>,
  ) => VNodeChild
  renderFilter?: (
    options: RendererOptions,
    params: TableGlobalFilterRendererParams<Row>,
  ) => VNodeChild
  renderToolbar?: (
    options: RendererOptions,
    params: TableGlobalToolbarRendererParams<Row, QueryForm>,
  ) => VNodeChild
}

The following fields are the main values available directly on each params object. Every method also receives the inherited control size; set options.props.size on one renderer to override it for that rendered component.

MethodAvailable params fields
renderDefaultrow, column, value, index, rowIndex, columnIndex, depth, expanded, loading, toggleExpand
renderEditrow, draftRow, column, value, setValue, commit, cancel, validation state
renderFormItemmodel, field, value, setValue, validate, submit, reset
renderFiltercolumn, values, setValues, apply, reset, close; value is the current control draft
renderToolbarsize, placement, disabled, action, source.table, source.context, source.busy

Body, edit, and filter parameters also contain the common FormRendererParams fields. params.source points to the original Table context before it enters the shared renderer. An events callback receives the matching stage params first, followed by the component event arguments.

Complete RendererOptions type:

interface RendererOptions<Model extends object = FormModel> {
  name: string
  component?: Component | string
  props?: Record<string, unknown>
  attrs?: Record<string, unknown>
  events?: Record<
    string,
    (params: FormRendererParams<Model>, ...args: unknown[]) => unknown
  >
  modelProp?: string
  modelEvent?: string
  changeEvent?: string
  content?: string | ((params: FormRendererParams<Model>) => VNodeChild)
  options?: unknown[]
  optionProps?: Record<string, string>
  children?: RendererOptions<Model>[]
}

Form and Table column configurations select a registry entry through name. Toolbar entries use itemRender, which is normalized to RendererOptions before invocation, so callback code still reads the name from options.name. props, attrs, and options are passed to the target component; a business renderer can narrow unknown[] to its own option type.

Built-in renderers

The input renderers show plain text through renderDefault and use the corresponding component for renderEdit, renderFormItem, and renderFilter.

RendererComponent or behavior
$inputSInput
$textareaSTextarea
$dateSDatePicker
$dateRangeSDatePicker with type="daterange"
$timeSTimeSelect
$timePickerSTimePicker
$selectSSelect
$radioSRadioGroup
$checkboxSCheckbox
$checkboxGroupSCheckboxGroup
$treeSelectSTableSelect with tree mode
$cascaderSCascader
$rateSRate
$sliderSSlider
$switchSSwitch
$verCodeSVerificationCode
$buttonsReusable action group for display, Form actions, and Table toolbars

$buttons.options contains action records with code, text, icon, visible, disabled, loading, props, and optional onClick. Omit props.maxVisible to keep every visible action inline; when it is set, the chosen number stays inline and the rest move into SPopper. The overflow trigger uses a vertical three-dot icon by default and accepts props.moreIcon as an explicit replacement. props.trigger accepts click or hover. In Form, unhandled submit and reset codes call the current Form methods.

Table also registers these toolbar-only renderers:

RendererBehavior
buttonOne SButton, or an SPopper action menu when props.children is present
$refreshRefresh the current Table query or proxy request
$columnConfigOpen STableColumnConfig for the current Table
$findMount an icon trigger that opens a find-and-replace panel in SPopper; pass content or props.content for a label. Each open resets the form. A successful search collapses to result controls; expand restores the form, and close or Escape dismisses the panel.

Input-surface renderers receive shape: 'square' by default during Table editing so their outline meets the cell edges. An explicit props.shape value overrides that default. Form fields and Table filters retain normal shape resolution.

Last Updated: 2026-10-28, 06:17:56 UTC
Copied