Skip to content

Latest commit

 

History

History
612 lines (518 loc) · 26.8 KB

plugin-grid.mdx

File metadata and controls

612 lines (518 loc) · 26.8 KB
title Plugin Grid

Advanced data grid with sorting, filtering, pagination, and row selection capabilities.

Installation

npm install @object-ui/plugin-grid

This package publishes a stylesheet. Import it after the base sheets, or the grid renders unstyled — the themed utilities it uses have no other source in a published app (#4929):

/* src/index.css */
@import "tailwindcss";
@import "@object-ui/components/style.css";
@import "@object-ui/fields/style.css";
@import "@object-ui/plugin-grid/style.css";

The props an object-grid node reads on a page are generated from the spec into the component reference; this page covers using the plugin from React.

Features

  • Sorting - Multi-column sorting support
  • Filtering - Column-level filtering
  • Pagination - Built-in pagination controls
  • Row Selection - Single and multi-row selection
  • Custom Cells - Custom cell renderers
  • Responsive - Mobile-friendly layouts

Usage

Registration is a side effect of the import

import '@object-ui/plugin-grid';

That single import is the whole of registration — there is no components map to iterate over. Importing the entry runs the two ComponentRegistry.register(...) calls in packages/plugin-grid/src/index.tsx, which claim exactly these schema types:

Namespaced key Bare-name fallback Renderer behind it
plugin-grid:object-grid object-grid ObjectGridRenderer — the data grid, queried from an object
view:grid none — skipFallback: true the same renderer, under the view protocol

ComponentRegistry.register publishes namespace:type, and — unless the call passes skipFallback: true — the bare type as a back-compat fallback (packages/core/src/registry/Registry.ts:194, fallback at :226).

The import-wizard node key is RETIRED (objectui#10859 batch 8): no schema produced it, and objectui validate refused it at type. ImportWizard is still exported, and @object-ui/app-shell mounts it directly (the object view's import flow).

Bare grid is deliberately not this plugin's. skipFallback: true on the view:grid call keeps the data grid from claiming it, because grid belongs to the CSS Grid layout container in @object-ui/components (packages/components/src/renderers/layout/grid.tsx:50). Reach the data grid as object-grid, or as view:grid when you want the namespaced spelling.

Registering the renderer under your own key

To serve the data grid under a key of your own, register the exported renderer — that is what a manual registration is here:

import { ComponentRegistry } from '@object-ui/core';
import { ObjectGridRenderer } from '@object-ui/plugin-grid';

ComponentRegistry.register('my-grid', ObjectGridRenderer, {
  namespace: 'my-app',
  label: 'My Grid',
  category: 'plugin',
});

ObjectGrid, ObjectGridRenderer, VirtualGrid, SplitPaneGrid, ImportWizard, InlineEditing and FormulaBar are on the package's export surface, alongside the hooks (useGroupedData, useColumnSummary, useCellClipboard, …) and the component prop types (ObjectGridComponentProps, VirtualGridProps, …). There is no aggregate map among them, and the schema types are not here either — they live in @object-ui/types, because the schema is the shared authoring contract rather than this package's component API.

Features

Sorting

Columns sort by default. sortable is a per-column key, used to turn a column off; the grid-level sort declares the order the grid opens with. There is no top-level sortable switch.

{
  "type": "object-grid",
  "properties": {
    "objectName": "users",
    "sort": [{ "field": "created", "order": "desc" }],
    "columns": [
      { "field": "name", "label": "Name" },
      { "field": "email", "label": "Email", "sortable": false }
    ]
  }
}

A click on a sortable column header sorts by that column; another click on it changes the direction.

On an object's list page the header opens a menu instead (objectstack#35876), which its host turns on (the headerMenu component prop, not a schema key): Sort ascending, Sort descending and Hide column. A column that does not sort offers Hide column alone. The header itself never changes the sort. Enter, Space or ArrowDown on the focused header opens the same menu; the arrows move through it, Enter chooses and Escape closes it without touching the sort.

  • With no sort, or a single level, the column picked in the menu replaces the sort.
  • With two levels or more it becomes the first level and every other level keeps its place after it; a column already in the sort moves up with the picked direction. No level is dropped.
  • The ↑1 / ↓2 marks on the headers show each level's place.
  • A sort chip under the view bar opens every level in one panel (it does not reverse the direction). Each level's handle reorders it: drag it to another row, or press ArrowUp / ArrowDown on the focused handle.

Filtering and search

There is no per-column filter key and no top-level filterable switch. A grid narrows its query two ways: a filter baked into the metadata, and a toolbar search over the fields named in searchableFields.

{
  "type": "object-grid",
  "properties": {
    "objectName": "users",
    "filter": [
      { "field": "status", "operator": "equals", "value": "active" },
      { "field": "created", "operator": "after", "value": "2026-01-01" }
    ],
    "searchableFields": ["name", "email"],
    "columns": ["name", "email", "status"]
  }
}

Row Actions

rowActions and bulkActions are lists of action names — the actions themselves live in the object's action set, so the same action behaves identically wherever it is offered. They are string[], not inline definitions carrying callbacks.

{
  "type": "object-grid",
  "properties": {
    "objectName": "users",
    "columns": ["name", "email"],
    "rowActions": ["view", "edit", "delete"],
    "selection": { "type": "multiple" },
    "bulkActions": ["delete", "export"]
  }
}

A name in bulkActions runs that action once per selected record. If the action declares params, the selection bar's dialog collects them once, before the run, and resolves them as the record page's action dialog does. A field-backed param ({ "field": "crm_campaign", "objectOverride": "crm_campaign_member" }) takes its type, label, options, default and picker target from that field, so a lookup param renders the record picker and the confirm step shows the picked record's label. A param whose field is not in the object metadata is refused, and the run is blocked.

The confirm step lists the affected records by their display title — the object's nameField, resolved as the record header resolves it — for every bulk action, whether it runs once per record or once over the selection. A record with no title to show is listed as Record # followed by its id.

The selection bar offers a write only to a caller who may make it. A bulk Delete is the rowDelete row of the affordance-to-grant map (@object-ui/core), and a bulkActionDefs entry with operation: 'update' — a patch written to every selected record — is the rowEdit row, the same rows the row menu's Delete and Edit read: the object's policy, the effective API operation set and the caller's delete or update grant. A closed row removes the button, and with it the dialog, its undo and its retry. custom entries are unchanged. With no permission provider mounted both read open.

Edit and Delete also fold the server's verdict on each row: writeScope, sharing rules and row-level security can refuse a record the object grant allows. The grid asks for that verdict (POST /api/v1/security/explain, one batch per operation for the rows on the page) when a row's actions are first reached for — a pointer or the focus on the actions cell, or a row menu opening — and never on the list's first paint. Until the answer lands every row keeps the object-level verdict, and an open menu shows Edit and Delete inert; an item the answer refuses then goes. A failed or missing answer keeps the object-level verdict.

Row callbacks are component props

onRowClick, onRowSelect, onCellChange, onRowSave, onBatchSave, onEdit, onDelete, onBulkDelete and onAddRecord are React props on ObjectGridComponentProps. They are functions, so no metadata document can hold them, and writing one of them into a schema does nothing at all: the grid builds the inner table's handlers itself and never reads any of these nine off the schema.

The one callback the grid does read off the schema is onNavigate, declared on ObjectGridSchema for programmatic callers only. It is a function value too, so it is no more authorable than the nine — it is deliberately absent from the manifest and the designer panel, and prefer passing it as a prop (objectui#5234, maintainer ruling of 2026-08-19).

import { ObjectGrid } from '@object-ui/plugin-grid';
import type { ObjectGridComponentProps } from '@object-ui/plugin-grid';

export const Grid = (props: ObjectGridComponentProps) => (
  <ObjectGrid
    {...props}
    onRowClick={(record) => console.log('Row clicked:', record)}
    onRowSelect={(rows) => console.log('Selection changed:', rows)}
  />
);

Note onRowSelect — the prop that reports a selection change is spelled that way; there is no onSelectionChange on this component.

The declarative alternative, which is metadata and survives a round trip through storage, is navigation: its mode decides what a row click does without any host code.

Withholding a row's Edit or Delete

operations and the onEdit / onDelete wiring are GRID-level: they decide whether the generic Edit / Delete entries exist at all, identically for every row. When the refusal belongs to one RECORD — a system field a designer may not drop — use rowOperations, a component prop called with a row record that answers for that row alone. Mounting <ObjectGrid> directly hands it the node as it reads it, so its schema prop is the flat ObjectGridSchema, with no bag:

import { ObjectGrid } from '@object-ui/plugin-grid';
import type { ObjectGridSchema } from '@object-ui/types';

const schema: ObjectGridSchema = {
  type: 'object-grid',
  objectName: 'field_definition',
  columns: ['name', 'label', 'type'],
};

export const FieldList = ({ isSystem }: { isSystem: (name: string) => boolean }) => (
  <ObjectGrid
    schema={schema}
    onEdit={(record) => console.log('edit', record)}
    onDelete={(record) => console.log('delete', record)}
    rowOperations={(record) => ({ delete: !isSystem(String(record.name)) })}
  />
);

It speaks the same update / delete vocabulary as the authored operations block, and it is an intersection, never a union: false withholds the entry, while true, an omitted member, and a null / undefined return all leave the grid's own verdict alone. Nothing it returns can re-open what the object's lifecycle bucket, its userActions, the server's effective operations, the principal's grant or the record-level verdict already closed — and a grid that passes no rowOperations renders exactly as it did before the prop existed.

Prefer this over refusing inside the callback. A refusal that runs after the click ships a button that is drawn as available and then does nothing, which is indistinguishable from a broken build (objectui#8674).

A node beside a row's title

A host that has something to say about one record, next to its name, passes rowAdornment: a component prop called with a row record that returns a React node, or null for none. The grid draws it in the cell of the object's declared nameField when a column shows that field, else in the first shown column (never in the row actions), and beside the card's title in the card view. It is drawn after the cell's own content and never in place of it, so the value, its link and its mask stay as they were. A grid that passes no rowAdornment renders exactly as it did before the prop existed. It is a host prop, not a schema key: list metadata cannot set it.

import { ObjectGrid } from '@object-ui/plugin-grid';
import type { ObjectGridSchema } from '@object-ui/types';

const schema: ObjectGridSchema = {
  type: 'object-grid',
  objectName: 'sys_user',
  columns: ['name', 'email'],
};

export const UserList = ({ needsAccess }: { needsAccess: (id: string) => boolean }) => (
  <ObjectGrid
    schema={schema}
    rowAdornment={(record) => (needsAccess(String(record.id)) ? <span>Not authorized</span> : null)}
  />
);

The console's Setup → Users list on a cloud-managed environment uses it to mark a user who holds no permission set beyond the baseline (objectui#13330).

Rows that open nothing

A host that owns the row click (onRowClick) and knows that it opens nothing for these rows passes rowOpensRecord={false}. The grid then draws its record-link cells (the first column, and any column authored link: true) as plain text, with no anchor and no ARIA link semantics, and the row's right-click menu offers no Open or Open in new tab; the row's actions stay. The row click still reaches onRowClick, so anything else the host does with it is unchanged. On a phone, where the grid draws each row as a card, the card draws no pointer and no hover wash, and its "⋮" stays (objectstack#33548). Absent (or true), every row is drawn as before. It is a host prop, not a schema key: list metadata cannot set it. The console passes false for a view authored navigation: { mode: 'none' } or navigation.preventNavigation: true (whatever its mode, objectstack#33549) and for an object whose data API serves no single-record read (objectstack#33317).

Inline Editing

Enable inline cell editing for quick data updates:

{
  "type": "object-grid",
  "properties": {
    "objectName": "users",
    "columns": [
      { "field": "id", "label": "ID" },
      { "field": "name", "label": "Name" },
      { "field": "email", "label": "Email" },
      { "field": "status", "label": "Status", "type": "select" }
    ],
    "editable": true,
    "singleClickEdit": false
  }
}

editable is the only switch: it is a grid-level flag, and edits persist through the host's data source (dataSource.update) with no callback to wire.

Features:

  • Double-click to edit: double-click any editable cell to enter edit mode (singleClickEdit: true opens it on the first click instead)
  • Keyboard shortcuts: press Enter on a focused cell to start editing, Enter again to save, Escape to cancel
  • Per-field read-only: which cells open is decided by the field definition, not by a column key — a field marked readonly, and computed/binary field types (formula, autonumber, file, …), never open an editor. There is no editable key on ListColumn.
  • Visual feedback: editable cells show a hover state, and the input is focused and selected when editing begins
  • The editor floats over its cell (objectstack#35688): it opens on a layer anchored to the cell's top-left corner, at least as wide as the column and wider where its field type needs it (an address form, a record picker), so the row keeps its height and no other column moves. Near the bottom of the window the layer opens upward, near the right edge it shifts left, and a cell half hidden behind a frozen column or the header is scrolled into view first. Scrolling the cell out of sight commits the edit.

To own persistence in a React host, supply onCellChange as a component prop — it is not a schema key.

On an object's list page

The console's list page draws its grid with the select-first cell model (objectstack#35684, objectstack#35687), which its host turns on (the cellSelection component prop, not a schema key). There is no inline-edit mode and no toggle: the grid is editable wherever the reader may edit the object and the view does not declare userActions.editInline: false, and singleClickEdit is not read there.

  • A click selects a cell (a ring around it); it neither edits nor opens the record. A link a cell draws (the name, a lookup, a phone or an email) keeps its own click. On a touch screen a tap opens the record.
  • A cut-off value shows in full when its cell is selected: a long text, a multi-line text or a list of tags that the column truncates opens on a layer over the cell, wrapped, scrolling inside past a few lines. Escape, an arrow key or a click elsewhere closes it; Enter or a double-click turns it into the editor in the same place and at the same size.
  • Editing starts on a double-click, Enter or F2 (the value kept, caret at its end), or by typing, which replaces the value; an input method's composition is kept whole. Backspace or Delete opens an empty editor and saves nothing yet.
  • While editing, Enter commits and moves down, Tab / Shift+Tab commit and move right / left, and Escape cancels and keeps the cell selected. In a multi-line editor Enter is a new line and Ctrl/Cmd+Enter commits. A click elsewhere commits.
  • Selected cell keys: the arrows and Tab move the selection; Space is typed like any other key and opens the editor (a checkbox cell flips instead, as do Enter and a second click on it); Ctrl/Cmd+C copies; Ctrl/Cmd+V converts the text to the field's type and commits it; Escape clears the selection. The record opens from the name link, or a tap on a touch screen.
  • A cell that opens no editor says why on the cell: the field is read-only, calculated or not editable in a list, the reader may not edit the field, the object or the record, the view turned editing off, or the record is locked by an approval.

Each commit is saved at once (objectstack#35685), as one update for that record; there is no Save All bar, no row Save / Cancel and no amber row. The cell shows a small spinner while its save runs and a check mark once it landed. Only that row is redrawn, from the record the server answered with (a value a server hook rewrote shows as stored); the list is not read again, so a row whose new value would sort it elsewhere stays in place until the next load (a refresh, a sort, a filter or a page change).

  • A refused save keeps the typed value and shows the server's reason on the cell. Escape puts the stored value back. A later edit on the same row is sent together with the refused one, as one update. When the reason names a field the list cannot edit, the notice offers to open the record.
  • A newer version (409) still opens the conflict dialog: "Reload latest" re-reads the list, "Overwrite anyway" writes over it and keeps the row in place.
  • Undo takes a save back: the save toast's Undo button, or Ctrl+Z (Cmd+Z on macOS) on a cell of the grid, newest save first. An undo is a new update that writes the value the record held before the save, guarded by the version this grid's own newest write of the record answered: if someone else changed the record since, the 409 dialog opens instead of their change being overwritten. The record's history shows the save and its undo as two changes. Each save is taken back once, and a refused or cancelled undo is used up too, so the next Ctrl+Z undoes the save before it. A toast's Undo takes back that toast's save, while Ctrl+Z always goes newest first. Inside an open editor Ctrl+Z stays the editor's own text undo. A save of a field the row did not read offers no Undo.
  • A state-machine field asks first. When the object's state_machine validation rule governs the field (an active rule whose events cover an update), picking a new value — in the cell's editor, or by pasting — opens a confirm that names the field and both values and says saving may trigger related automation ("Status changes from On Hold to Active. Saving may trigger related automation."). Cancel writes nothing and the cell keeps the value it had; Change saves it as any commit is saved. The confirm does not list the flows. A host asks this through GridCellSelection.confirmCommit.
  • The record drawer follows. A record open in the list's drawer is read again when a list cell saves it. If the drawer holds unsaved edits of its own, those stay as typed, the drawer's save bar says the record was changed elsewhere, and Save writes the drawer's edits over the latest version.

Footer calculations

A column's summary draws its calculation in the table's last row, under the column. A host that passes residentSummaryRow draws that row on a flat table even when nothing is declared, led by the record count. With onColumnSummaryPick as well (wired only for a reader who may change the view), clicking a cell opens one menu of the calculations its field type allows, the current one ticked and None last; the grid draws the pick at once and the host saves it as the column's summary (an answer of false takes the pick back). summaryPickFields limits the menu to the columns the host can save. The console's list offers it on the columns the view declares and saves only the calculation: on a personal view at once, and on a shared view as a draft, which the list draws, for the editor and everyone else, once it is published.

Keyboard navigation

keyboardNavigation turns the grid's data cells into one roving Tab stop, on the WAI-ARIA grid pattern (objectui#11068):

{
  "type": "object-grid",
  "properties": {
    "objectName": "users",
    "columns": ["name", "email", "status"],
    "keyboardNavigation": true
  }
}
  • One Tab stop. Tab reaches the cells once — on the cell that last held focus, or the first cell of the first row — and the next Tab moves past them. A widget a cell renders (the record link, a row's action menu, a selection checkbox) keeps its own Tab stop.
  • Arrow keys move focus one cell; Home / End go to the first / last cell of the row, and Ctrl+Home / Ctrl+End to the first / last cell of the page. At an edge, focus stays put.
  • Editing. On an editable grid, Enter still opens the focused cell, and an open cell's editor keeps every key. An edit ended with Enter or Escape hands focus back to its cell, so the arrows carry on from there.
  • Default. On when the grid renders editable — the authored editable and the viewer's permission to update the object, the same value inline editing obeys. A read-only grid keeps every cell its own Tab stop unless you write true, and false turns it off on an editable grid.
  • While it is on, the table is exposed to assistive technology as a grid. A grouped grid navigates within each group's table; the mobile card layout has no cells and is unaffected.

Batch Editing & Multi-Row Save

Edit multiple cells across multiple rows and save them individually or all at once. This is the model of a grid without the select-first cell model (a related list, a dashboard table, an object-grid outside a list page); a list page saves each cell as it is committed (above). The schema half is just editable — the save/cancel affordances appear on their own once a row has pending changes:

{
  "type": "object-grid",
  "properties": {
    "objectName": "products",
    "columns": [
      { "field": "sku", "label": "SKU" },
      { "field": "name", "label": "Name" },
      { "field": "price", "label": "Price", "type": "currency", "align": "right" },
      { "field": "stock", "label": "Stock", "type": "number", "align": "right" }
    ],
    "editable": true
  }
}

Left alone, saving goes through the host's data source. A React host that needs to own persistence supplies onRowSave / onBatchSave as component props — and because they are props, they take the adapter from the host's own scope rather than from anything in the schema:

import type { ObjectGridComponentProps } from '@object-ui/plugin-grid';

type Persistence = Pick<ObjectGridComponentProps, 'onRowSave' | 'onBatchSave'>;

const persistence = (
  dataSource: NonNullable<ObjectGridComponentProps['dataSource']>,
): Persistence => ({
  onRowSave: async (rowIndex, changes, row) => {
    await dataSource.update('products', row.id, changes);
  },
  onBatchSave: async (allChanges) => {
    await Promise.all(
      allChanges.map(({ row, changes }) => dataSource.update('products', row.id, changes)),
    );
  },
});

Features:

  • Pending changes tracking: edit multiple cells across rows before saving; a cell edited back to the value it loaded with is not a pending change, and its row is no longer counted as modified
  • Visual indicators: modified rows highlighted in amber, modified cells in bold
  • Row-level save/cancel: individual row save and cancel buttons
  • Batch operations: Save All and Cancel All buttons for bulk actions
  • Flexible callbacks — all three are ObjectGridComponentProps, never schema keys: onRowSave for a single row, onBatchSave for many, onCellChange for each committed cell edit, including one that leaves the value as loaded (only a real change is staged)
  • A concurrent write is refused, not overwritten: the default saves send each row's updated_at as If-Match, and an editable grid asks for that column even when no column shows it. A row someone else saved after it was read answers 409, which opens the record page's conflict dialog (Reload latest, Overwrite anyway, Cancel). "Save All" reports each row on its own: a refused row stays pending and flagged, and the rows that saved are cleared.

TypeScript Support

The schema and column types come from @object-ui/types; this package exports the component types. Neither GridSchema nor GridColumn is on this package's export surface, and both names are taken elsewhere by different things — GridSchema in @object-ui/types is the CSS Grid layout container, and GridColumn in @object-ui/fields is a column of the line-items form widget (keyed name). The data-grid pair is ObjectGridSchema + ListColumn. ObjectGridSchema types the component's schema prop — the node as the grid reads it, after SchemaRenderer hoists an authored node's properties bag onto it — so its keys sit flat here.

import type { ObjectGridSchema, ListColumn } from '@object-ui/types';
import type { ObjectGridComponentProps } from '@object-ui/plugin-grid';

const nameColumn: ListColumn = {
  field: 'name',
  label: 'Full Name',
  sortable: true
};

const grid: ObjectGridSchema = {
  type: 'object-grid',
  objectName: 'users',
  columns: [nameColumn],
  pagination: { pageSize: 20 }
};

// Row callbacks are COMPONENT props, not schema keys.
const gridProps: ObjectGridComponentProps = {
  schema: grid,
  onRowClick: (record) => console.log('Row clicked:', record)
};

Annotating the literal is the point: an un-annotated const schema = { … } type-checks no matter what is written in it, so a snippet that carries no annotation cannot tell you whether its keys are real.

License

MIT