Skip to Content
TelamonJS

ExportButtons

Export dropdown and buttons for CSV, Excel, and PDF downloads

Export UI for tabular data. Two complementary surfaces exist in the library:

  • ExportButtons (+ ExportPDFButton, ExportExcelButton) — a dropdown button where you provide the export handlers; only the formats you pass a handler for appear in the menu.
  • ExportMenu + exportToCSV / exportToExcel / exportToPDF / exportTableData — batteries-included export for TanStack ColumnDef-based tables (used by DataTable), generating the files client-side. Excel and CSV need no extra package; PDF loads the optional jspdf + jspdf-autotable peers on first use.

What is exported

The exports are ExportButtons, ExportPDFButton, ExportExcelButton, ExportMenu, and the exportTo* utilities documented below. There is no JSON export built in.


Basic Usage

import { ExportButtons, type ExportColumn } from '@telamonjs/ui'

const columns: ExportColumn<User>[] = [
  { header: 'Full Name', accessorKey: 'name' },
  { header: 'Email', accessorKey: 'email' },
  { header: 'Member Since', accessorFn: u => u.createdAt.toLocaleDateString() },
]

export default function UsersToolbar({ users }: { users: User[] }) {
  return (
    <ExportButtons
      data={users}
      columns={columns}
      filename='users-export'
      onExportCSV={async (data, cols, filename) => {
        // Your export implementation (or delegate to exportToCSV — see below)
      }}
    />
  )
}

The dropdown renders only the entries whose handler you passed (onExportPDF, onExportExcel, onExportCSV). With no handler at all, the component renders nothing.


Props

ExportButtons

Prop

Type

ExportColumn

Prop

Type

ExportPDFButton / ExportExcelButton

Single-format standalone buttons — same data/columns/filename/disabled/ className props, plus the one required handler (onExportPDF / onExportExcel) and an optional label. There is no standalone CSV button — use ExportButtons with only onExportCSV.


Batteries-included: ExportMenu + exportUtils

When your columns are TanStack ColumnDefs (as in DataTable), skip writing handlers — ExportMenu generates the files itself. ColumnDef is TanStack's type, imported from @tanstack/react-table: @telamonjs/ui depends on it but does not re-export it, so add it to the app to import the type:

import { ExportMenu } from '@telamonjs/ui'
import type { ColumnDef } from '@tanstack/react-table'

<ExportMenu
  data={rows}
  columns={columns} // ColumnDef<T>[]
  filename='users'
  formats={['excel', 'csv', 'pdf']}
  pdfOptions={{ title: 'Users Report', orientation: 'landscape' }}
  onExportComplete={() => toast.success('Export complete')}
  onExportError={error => toast.error(error.message)}
/>

ExportMenu props

Prop

Type

Utility functions

await exportToExcel(data, columns, filename, options)  // .xlsx, written in-house (bold header row)
exportToCSV(data, columns, filename, options)          // .csv, UTF-8 with BOM
await exportToPDF(data, columns, filename, options)    // .pdf via the optional jspdf + jspdf-autotable peers
await exportTableData(data, columns, format, filename, options) // dispatch by format

interface ExportOptions {
  t: ReturnType<typeof useTelamonjsT> // required: library translator
  locale: string                    // required: formats dates in cells
  includeHiddenColumns?: boolean
  filename?: string
  sheetName?: string   // Excel only
  appendDate?: boolean // default true
}

interface PDFExportOptions extends ExportOptions {
  orientation?: 'portrait' | 'landscape'
  logo?: string | { src: string; width?: number; height?: number } // size in mm
  title?: string
  subtitle?: string
  footer?: string
  generatedAt?: 'datetime' | 'date'
}

All take TanStack ColumnDef<T>[] and download client-side with a date-stamped filename (users_2026-08-18.csv). options is required because headers and values are localized: pass the library translator and the active locale. exportToExcel, exportToPDF and exportTableData return a promise that resolves once the download starts; await it to catch failures. Without the jspdf peers, exportToPDF rejects with an error naming both packages (ExportMenu shows it as a toast). Excel sheet names follow Excel's rules: at most 31 characters, and \ / ? * [ ] : become spaces.

Wiring them into ExportButtons handlers:

'use client'

import { useLocale } from 'next-intl'
import { ExportButtons, exportToCSV, useTelamonjsT } from '@telamonjs/ui'

export function UsersExport({ users }: { users: User[] }) {
  const t = useTelamonjsT()
  const locale = useLocale()

  return (
    <ExportButtons
      data={users}
      columns={exportColumns}
      filename='users'
      onExportCSV={async data => exportToCSV(data, columnDefs, 'users', { t, locale })}
    />
  )
}

Which one do I use?

SituationUse
DataTable/ListPage toolbar, ColumnDef columnsExportMenu (or DataTable's built-in export)
Custom export pipeline (server-generated file, API call)ExportButtons with your handlers
One format only, PDF or ExcelExportPDFButton / ExportExcelButton
Programmatic export (no UI)exportToCSV / exportToExcel / exportToPDF

Best Practices

  1. Limit data - Don't export 100,000+ records client-side; generate large files on the server and download the URL
  2. Format values - Use accessorFn (ExportColumn) or cell accessors (ColumnDef) for dates and currency
  3. Descriptive filenames - The utilities append the date automatically
  4. Error handling - ExportButtons logs handler errors; surface feedback via ExportMenu's onExportError or your own toasts
  5. Permissions and audit - Enforce who can export on the server, and log exports for compliance

Accessibility

  • Trigger and menu are the library's DropdownMenu (Radix): keyboard navigable, focus managed, Esc closes
  • The trigger disables itself while exporting or when data is empty

On this page