Toolforge Docs
DocsBlock Outputstable

table

Display structured data in a tabular format with customizable columns and formatting.

Usage

Table

const table = block.table({
  title: 'Users',
  data: [
    { id: 1, name: 'Alice', email: 'alice@example.com' },
    { id: 2, name: 'Bob', email: 'bob@example.com' },
  ],
  columns: [
    { key: 'ID', label: 'id' },
    { key: 'Name', label: 'name' },
    { key: 'Email', label: 'email' },
  ],
})

Props

PropDescriptionTypeRequiredDefault
titleTitle displayed above the tablestringNoundefined
descriptionDescription text below the titlestringNoundefined
dataArray of row data objectsRecord<string, unknown>[]Yes
columnsColumn configurationTableColumn[]Yes

TableColumn

PropertyDescriptionTypeRequired
headerColumn header textstringYes
accessorKeyKey to access data from rowstringYes
renderCustom render configurationTableRenderConfigNo

TableRenderConfig

PropertyDescriptionType
typeRender type'badge' | 'currency' | 'link' | 'progress' | 'text'
variantBadge variant (when type is 'badge')'default' | 'secondary' | 'destructive' | 'outline'
currencyCurrency code (when type is 'currency')string
hrefURL or accessor key for link (when type is 'link')string
maxMaximum value for progress (when type is 'progress')number

Returns

Returns a table block that can be returned from a handler or passed to io.message().

Examples

Basic table

Basic table

return block.table({
  title: 'Team Members',
  data: [
    { name: 'Alice', role: 'Engineer', department: 'Engineering' },
    { name: 'Bob', role: 'Designer', department: 'Design' },
    { name: 'Charlie', role: 'Manager', department: 'Operations' },
  ],
  columns: [
    { label: 'Name', key: 'name' },
    { label: 'Role', key: 'role' },
    { label: 'Department', key: 'department' },
  ],
})

With badge rendering

With badge rendering

return block.table({
  title: 'Orders',
  data: orders,
  columns: [
    { label: 'Order ID', key: 'id' },
    { label: 'Customer', key: 'customer' },
    {
      label: 'Status',
      key: 'status',
      renderConfig: {
        type: 'badge',
        variant: 'default',
      },
    },
  ],
})

With progress bars

With progress bars

return block.table({
  title: 'Project Progress',
  data: projects,
  columns: [
    { label: 'Project', key: 'name' },
    {
      label: 'Completion',
      key: 'progress',
      renderConfig: {
        type: 'progress',
        maxValue: 100,
      },
    },
    { label: 'Due Date', key: 'dueDate' },
  ],
})

With progress bars

return block.table({
  title: 'Repositories',
  data: repos,
  columns: [
    {
      label: 'Name',
      key: 'name',
      renderConfig: {
        type: 'link',
        target: '_blank',
      },
    },
    { label: 'Stars', key: 'stars' },
    { label: 'Language', key: 'language' },
  ],
})

Mixed render types

Mixed render types

return block.table({
  title: 'Sales Report',
  description: 'Q4 2024',
  data: salesData,
  columns: [
    { label: 'Product', key: 'product' },
    {
      label: 'Revenue',
      key: 'revenue',
      renderConfig: { type: 'default' },
    },
    {
      label: 'Status',
      key: 'status',
      renderConfig: { type: 'badge', variant: 'default' },
    },
    {
      label: 'Target',
      key: 'targetProgress',
      renderConfig: { type: 'progress', maxValue: 100 },
    },
  ],
})

With error badge

Mixed render types

return block.table({
  title: 'Error Log',
  data: errors,
  columns: [
    { label: 'Time', key: 'timestamp' },
    { label: 'Message', key: 'message' },
    {
      label: 'Severity',
      key: 'severity',
      renderConfig: {
        type: 'badge',
        variant: 'error',
      },
    },
  ],
})

On this page