CellFormatter#
@palmyralabs/rt-forms · src/palmyra/grid/base/utils/CellFormatter.ts
Overview#
Utility module — not a React component. A set of functions that convert a raw cell value into its displayed representation, consumed by ColumnConverter.generateColumns when it builds @tanstack/react-table column defs. Delegates to DataFetchUtil.formatValue for the common case, with a specialised BIT renderer for boolean-like columns.
Exports#
// BIT columns with a 1/0 → "Yes"/"No" style displayPattern
function formatBIT(columnDef: ColumnDefinition): (info: CellContext<any, any>) => string;
// Generic delegate — calls DataFetchUtil.formatValue against the column's type/pattern
function formatColumn(columnDef: ColumnDefinition): (info: any) => any;
// Returns an object spreadable into a TanStack column definition
function getFormatFn(columnDef: ColumnDefinition): { cell: (info: CellContext<any, any>) => any };info.getValue() is the row’s raw attribute value; the returned string/JSX is what the cell renders.
displayPattern — the BIT example#
{
attribute: 'active',
name: 'active',
label: 'Active',
type: 'BIT',
displayPattern: [{ '1': 'Yes' }, { '0': 'No' }],
}formatBIT looks up the value against each entry in displayPattern and returns the mapped string. Anything else falls through to the stringified value.
Example — override in a custom column#
Most columns don’t need this directly — pass a cellRenderer in your ColumnDefinition and ColumnConverter will use it. Reach for getFormatFn when you are building TanStack column defs by hand:
import { createColumnHelper } from '@tanstack/react-table';
import { getFormatFn } from '@palmyralabs/rt-forms';
const columnHelper = createColumnHelper<User>();
const columns = [
columnHelper.accessor('status', {
header: 'Status',
...getFormatFn({ attribute: 'status', name: 'status', label: 'Status',
type: 'BIT',
displayPattern: [{ 'ACTIVE': 'Active' }, { 'ARCHIVED': 'Archived' }] }),
}),
];