Overview
What a Grist custom widget is, what grist-widget-sdk does for one, and when to use Grist's plugin API on its own.
A Grist custom widget is a web page that Grist shows in a section of a
document, in an iframe. Grist hands it the selected table and row, and
lets it write back, through grist-plugin-api.js: a global grist
object with a handshake (grist.ready), event streams (onRecord,
onRecords, onOptions) and a channel to the document (docApi). The
widget can be anything a page can be: a chart, a form, a map, a kanban
board.
What the SDK does
grist-widget-sdk is a React library on top of that API. A widget made
with it is one declaration and one component:
import { defineGristWidget } from "grist-widget-sdk"
export const widget = defineGristWidget({
title: "Task",
requiredAccess: "full",
columns: [
{ name: "Title", type: "Text" },
{ name: "Done", type: "Bool" },
],
})
export default function App() {
const w = widget.useGrist()
if (!w.mappedRecord) return <p>Select a task in Grist.</p>
const { Title, Done } = w.mappedRecord
return (
<button onClick={() => w.updateRecord({ Done: !Done })}>
{Title}: {Done ? "done" : "to do"}
</button>
)
}From that, the SDK:
- asks Grist once for the access and the columns the declaration names, and lets the person map their own columns to them in Grist's panel;
- shows the waiting screens (connecting, access, columns to map) until the widget can render, and an alert when a write fails;
- gives typed records:
w.mappedRecordhasTitle: string | nullandDone: boolean | null, decoded from Grist's wire format and checked against the declared types; - writes back under the declared names (
w.updateRecord,w.addRecord), in the column the person mapped; - runs the same code in tests:
renderWithGrist(<App />, { widget, rows })mounts the widget against an emulated Grist, in Vitest, with no browser and no document.
The rest of the kit
create-grist-widgetscaffolds a widget repository: the SDK, Vite, Tailwind and shadcn/ui, tests, and a GitHub workflow that publishes every version to GitHub Pages, with a live preview of thedevbranch. Your first widget walks through it.- The catalog holds ready-made widgets built the same way, each with a demo in a real Grist running in your browser. A widget there is installed by pasting its URL into a custom widget section.
When the SDK isn't the tool
The SDK is for a widget written in React that runs inside a Grist document. It isn't the tool when:
- the widget isn't React: use
grist-plugin-api.jsdirectly, which works with any framework, or none; - you embed Grist in your own application: that is the host's side, done with Grist's embedding and REST API, not with a widget;
- you need something Grist doesn't let a widget do: the SDK goes through the plugin API, so it can't do more than it allows.
A widget made with the SDK never calls the grist global itself: the SDK
holds the one connection, and the template's lint rule refuses a direct
call.
Next
- Your first widget: scaffold, declare, read, write, test, release.
- The catalog: widgets to install, each with its demo in a real Grist, and its spec, code and tests to learn from.
- Core concepts: sections, records, mapping and access, as a widget sees them.