Data

DataTable

Sortable table with rich column formatting — currency, percent, delta, status badges, dates, links, and booleans. Client-side sorting with staggered row animations.

State

Top Customers by Revenue

Ranked by total lifetime revenue across all plans

CustomerRevenueGrowthPlanSince
Acme Corp$48,200+23.5%EnterpriseJan 15, 2023
Globex Inc$35,800-4.2%BusinessJun 1, 2022
Initech$29,100+12.8%EnterpriseAug 22, 2023
Umbrella Co$22,400+45.1%BusinessFeb 10, 2024
Soylent Corp$18,900+8.3%StarterMay 30, 2024
5 of 5 rowsBilling API· 5 min ago

Installation

Terminal
npx taw-ui add data-table

This copies the component source and schema into your project. You own the code — customize anything.

Usage

server — define tool
import { tool } from "ai"
import { DataTableSchema } from "@/components/taw/data-table"

export const showTable = tool({
  description: "Show data in a sortable table",
  parameters: z.object({ query: z.string() }),
  outputSchema: DataTableSchema,
  execute: async ({ query }) => {
    const result = await queryDatabase(query)
    return {
      id: slugify(query),
      title: result.title,
      columns: result.columns.map(c => ({
        key: c.key,
        label: c.label,
        type: c.type,
        sortable: true,
      })),
      rows: result.rows,
      total: result.total,
      defaultSort: { key: "revenue", direction: "desc" },
      source: { label: "Database", freshness: "just now" },
    }
  },
})
client — render
import { DataTable } from "@/components/taw/data-table"
import type { TawToolPart } from "taw-ui"

function ToolOutput({ part }: { part: TawToolPart }) {
  // Handles loading, error, and success states
  return <DataTable part={part} />
}

Column Types

9 built-in column types handle formatting without custom renderers.

FieldTypeDescription
textdefaultPlain string
numberformatLocale-formatted number with optional decimals
currencyformatCurrency-formatted with symbol (configurable via format.currency)
percentformatSigned percentage with color coding (green/red)
deltaformatArrow + signed number with color coding
dateformatLocale-formatted date (short month, day, year)
badgevisualPill badge with accent color
linkvisualClickable link with dotted underline
booleanvisualCheckmark (true) or cross (false)

Props

FieldTypeDescription
part*TawToolPartTool call lifecycle state — handles loading, error, and success
animatebooleanEnable stagger row animations (default: true)
classNamestringAdditional CSS classes on the wrapper

Schema

Cross-field validation ensures defaultSort.key exists in your columns — caught at parse time, not at render.

DataTableSchema
FieldTypeDescription
id*stringStable identifier
titlestringTable header title
descriptionstringSubtitle below the title
columns*Column[]Column definitions (min 1)
rows*Record[]Row data as key-value objects
totalnumberTotal row count (for pagination context)
defaultSort{ key, direction }Initial sort column and direction
confidencenumber (0-1)AI confidence badge
caveatstringUncertainty note
sourceSourceData provenance (label + freshness)
Column
FieldTypeDescription
key*stringMaps to row data keys
label*stringColumn header text
typeColumnTypeOne of 9 types (default: "text")
align"left" | "center" | "right"Text alignment (default: "left")
sortablebooleanEnable sort on this column (default: false)
widthstringCSS width (e.g. "120px", "20%")
format{ currency?, decimals? }Extra formatting options for currency/number types

Features

Client-side sorting

Click column headers to toggle asc/desc/none

9 column format types

Rich formatting without custom renderers

Cross-field validation

defaultSort.key must exist in columns, caught at parse time

Row count + source

Footer shows row count and data provenance

Staggered entrance

Rows animate in sequence on first render

Helpful errors

Invalid columns show field-level details with suggestions

Related