Skip to content

API Reference parrot.outputs.a2ui_renderers._table_format

github-actions[bot] edited this page Dec 2, 2026 · 4 revisions

parrot.outputs.a2ui_renderers._table_format

View source

Pure DataTable cell formatting, shared by both HTML renderers (FEAT-493, TASK-2711).

TableColumn.type/.format (parrot.models.outputs) already carry "the minimum information a frontend grid library needs to render a column correctly" — both renderers used to ignore it and render every cell as str(value). This module formats in Python, so ssr-html and pdf come out formatted with zero client-side JS, and interactive-html shares the exact same rules.

Pure, stateless functions only — no I/O, no renderer instance state — so they're directly testable and safe to call from three render call sites (interactive, SSR, and PDF via SSR) without any shared mutable context.

Attribute NUMERIC_TYPES

Type: frozenset[str]

Function format_cell

Format one cell value for display. Pure: no I/O, no renderer state.

format_cell(value: Any, *, col_type: str | None, col_format: str | None = None) -> str

Parameter Type Default Description
value Any The raw (already-resolved) cell value.
col_type str | None The column's declared TableColumn.type (string | integer | number | boolean | date | datetime | time | duration | any).
col_format str | None None The column's optional TableColumn.format hint (currency | percent | email | uri | enum | id | code) or number. Only currency/percent/number affect formatting here; the rest are display hints for a frontend grid library, not something this text-only renderer acts on.

Returns: str — The formatted display string. None always formats as an em dash, regardless of type: an empty cell in a printed table reads as a number someone lost, while "—" says there is nothing to report. The store rows with no scheduled visits are the case — they have no completion rate because they have no denominator, not because the figure went missing. A non-numeric type (or a value that fails numeric coercion) passes through as str(value) unmodified — a typed string column is NEVER comma-grouped or aligned, even if its value happens to look numeric (e.g. a zip code).

Function format_cell_html

Render one <td> for a DataTable cell, HTML-escaped.

format_cell_html(value: Any, *, col_type: str | None, col_format: str | None = None) -> str

Parameter Type Default Description
value Any The raw (already-resolved) cell value.
col_type str | None The column's declared TableColumn.type.
col_format str | None None The column's optional TableColumn.format hint.

Returns: str — <td class="num" data-v="<raw>"><formatted></td> for a numeric column (data-v carries the RAW, unformatted value so the existing client-side sort compares numbers rather than separator-laden text), or a plain <td><formatted></td> otherwise.

Function is_numeric_column

Whether a declared TableColumn.type renders as a numeric column.

is_numeric_column(col_type: str | None) -> bool

Parameter Type Default Description
col_type str | None The column's declared type (may be None when a caller omits it, e.g. a hand-authored envelope in a test).

Returns: bool — True for integer/number/duration only.

Architecture

Clients

Bots & Agents

Memory

Knowledge

Tools & Toolkits

Flows

Experts

Skills

Stores & Loaders

MCP & A2A

Server & APIs

Integrations

Outputs & A2UI

Prompts

Security

Operations

Migration

SDD Tooling

LLM Wiki

Deployment

Decisions

API Reference

Clone this wiki locally