REFERENCE
SDK Demos
How to use @asgard-js/core and @asgard-js/react, with demos you can try on the page.
TABLE / CHART Advanced
Beyond their basic rendering, the table and chart templates each carry a set of advanced
capabilities: TABLE can show the SQL that produced it and let the user take the data away,
CHART can offer several renderings of one dataset and let the user switch. Neither needs
any props — fill the fields in the template and the UI appears.
TABLE: the SQL Tab
The
tableobject has two optional fields:Field Type Purpose sqlstringThe query behind the table, shown in the SQL tab as a syntax-highlighted code block sqlExplanationstringAn explanation, rendered as Markdown below the SQL Either one being present grows a
Table/SQLtab pair above the table; with neither, no tab row renders at all and it is just an ordinary table. The two fields are independent — supplying onlysqlExplanationis valid, and the SQL tab then holds just the prose.TABLE: Download
The download button sits at the right of the title row, on the condition that you are on the Table tab and there is data (it disappears on the SQL tab). It opens two choices:
Format Output CSV Comma-separated; a value containing ,,"or a newline is quoted and its"escaped to"". The file is prefixed with a BOM so Excel reads non-ASCII text correctlyJSON Lines One JSON object per line, keyed by each column's keyThe filename is
<title>_<YYYY-MM-DD>.<ext>, with non-alphanumeric characters in the title replaced by underscores.It downloads all the data, not the current pagepaginationonly governs how many rows are on screen; the download always exports the whole ofdata. The entire file is generated in the browser from the current data — the backend is never asked again.Both formats export the formatted display values, not the raw ones — a
CURRENCYcolumn comes out as"$135,000", not135000. If you need the underlying numbers for further computation, this is not the right source.A snackbar appears afterwards offering to open the file you just downloaded, and dismisses itself after 5 seconds.
TABLE: Columns and Formats
interface TableData {
rowType: "OBJECT" | "ARRAY";
columns: { header: string; key?: string; format?: "DATE" | "DATE_TIME" | "CURRENCY" }[];
pagination: { size: number } | null;
data: Record<string, unknown>[] | unknown[][];
sql?: string;
sqlExplanation?: string;
}rowTypedecides how a cell is read out of a row, and what the header looks like:OBJECT— each row is an object, read viacolumn.key. The header shows two lines:headerabove,keybelow.ARRAY— each row is an array, read positionally (keyis unused). The header is the singleheaderline.
formatgoverns the cell's presentation:DATEgoes throughtoLocaleDateString(),DATE_TIMEthroughtoLocaleString(), andCURRENCYformats as TWD with no decimals. Without aformatthe value is stringified as-is;null/undefinedalways render as an empty string.CHART: Switching Between Renderings
chartOptionsis an array, one entry per rendering:Field Type Purpose chartOptions[].typestringThe identifier defaultChartmatches againstchartOptions[].titlestringThe name shown in the dropdown chartOptions[].specobjectA Vega or Vega-Lite spec defaultChartstringThe typeselected initiallyThe dropdown only appears with more than one optionWith a single option the chart still renders, but there is nothing to switch to, so no dropdown is drawn.
A
defaultChartthat matches notypesilently falls back to the first option's spec rather than erroring — so a typo just quietly renders the first chart.{
type: MessageTemplateType.CHART,
title: "Sales by Region",
text: "The same data in two renderings.",
defaultChart: "bar",
chartOptions: [
{ type: "bar", title: "Bar", spec: barSpec },
{ type: "line", title: "Line", spec: lineSpec },
],
}CHART: the SDK Rewrites Your Spec
The spec you supply is not drawn verbatim. The SDK clones it and changes two things:
- The background is forced to white. Deliberately — Vega's default axis and legend text is dark, and a transparent background would make it nearly invisible under a dark theme.
- The width tracks the container. A
ResizeObservermeasures the wrapper and writes it intospec.width, addingautosize: { type: "fit", resize: true, contains: "padding" }. So awidthof your own is overwritten;heightis left alone.
Vega's built-in actions menu (the save / view-source affordance) is always disabled.
See Also
- Message Templates — the full template catalog
- Theme — chat surface colors (the chart background is exempt, see above)