Skip to main content
A column type decides how a value is checked, parsed, formatted, compared and filtered. Column types lists the built-ins and the ColumnType contract. This guide writes one from scratch and carries it through every layer.

Write the type

A type is a plain object. This one stores a rating from 1 to 5 as an integer and shows it as stars.
rating.ts
parse returns undefined when the input does not parse. An edit or a paste with such a value is skipped. An empty input becomes null before parse is called.

Register it

createDefaultRegistry() holds the fourteen built-ins. register adds a type and returns the registry. Pass the registry to createSchema, and columns can use the new name in type. createTypeRegistry(types) starts from an empty registry instead, for a schema that should not see the built-ins.

Start from a built-in

Spreading a built-in keeps its parsing, formatting and operators and changes the rest. Column types registers an sku type this way, as text that shows as metadata on cards.

Render it

The grid draws a custom type with the renderer for its kind until you register one by name. Renderers are keyed by type name first, then by kind. See Custom renderers and editors.

Over HTTP

The server sends columns with their type names, not the type objects. A client that connects to a server using custom types passes the same registry, or schema creation fails with unknown_type.
http.ts
On the server, give createSchema the same registry before handing the schema to createKyselyAdapter and createTallyHandler. Requests are validated against it, so the custom operators and aggregates are checked like the built-ins. The SQL adapter compiles a column by its kind, so a number type compares and sums as a number. In Laravel, return extra types from types() on the grid class. ColumnType has factories per kind:
See Node and Laravel.

CSV import

detectColumnType from tally-core/import tries types in a fixed priority, then every other registered type with a detect function. A sample column whose values match detect is imported as the custom type. See CSV import and export.