Documentation
CSV Export (beta)
SimpleTable makes it easy to export your table data to CSV format with just one method call. Using the tableRef and the exportToCSV() method, users can download their data for analysis, reporting, or sharing.
Basic Usage
To enable CSV export in your table, follow these steps:
- Create a table reference - Create a ref using
useRefand pass it to thetableRefprop - Add an export button - Create a button or trigger that calls the export method
- Call exportToCSV() - Invoke
tableRef.current?.exportToCSV()to download the CSV file
CSV Export Configuration
✨ Full Data Export
The exportToCSV() method now exports all data from your table, including all pages when pagination is enabled. Previously, only the current page was exported - this has been fixed in version 1.9.4.
The exported CSV includes all visible columns and respects active filters/sorting. Default filename is table-export.csv. Customize with exportToCSV({ filename: "my-file.csv" }).
Formatting CSV Exports
Control how column values appear in CSV exports using three powerful options. By default, CSV exports use raw data values.
1. Use Formatted Values (useFormattedValueForCSV)
Export the same formatted values that are displayed in the table. Perfect when you want CSV exports to match what users see on screen.
1{2 accessor: "salary",3 label: "Annual Salary",4 valueFormatter: ({ value }) => `$${(value / 1000).toFixed(0)}K`,5 useFormattedValueForCSV: true6}78// Table displays: "$85K"9// CSV exports: "$85K"10// Without flag: CSV would export 85000
2. Custom Export Values (exportValueGetter)
Provide completely different values specifically for CSV export. Takes highest priority. Ideal for adding codes, identifiers, or transforming data for spreadsheet compatibility.
1{2 accessor: "completionRate",3 label: "Completion Rate",4 valueFormatter: ({ value }) => `${(value * 100).toFixed(1)}%`,5 exportValueGetter: ({ value }) => {6 // Round to whole percentage for CSV7 return `${Math.round(value * 100)}%`;8 }9}1011// Table displays: "92.5%"12// CSV exports: "93%"13// Raw value: 0.925
3. Adding Context to Exports
Use exportValueGetter to add department codes, identifiers, or additional context for better data clarity:
1{2 accessor: "department",3 label: "Department",4 valueFormatter: ({ value }) => capitalize(value),5 exportValueGetter: ({ value }) => {6 const codes = {7 engineering: "ENG",8 product: "PRD",9 sales: "SLS",10 marketing: "MKT"11 };12 const code = codes[value] || "OTH";13 return `${capitalize(value)} (${code})`;14 }15}1617// Table displays: "Engineering"18// CSV exports: "Engineering (ENG)"
Accessing Table Data
New in v1.9.4: The table ref now provides powerful methods to access all table data and configuration programmatically. Try clicking the "Get Table Info" button in the demo above!
getAllRows() - Access Complete Dataset
Returns all rows as TableRow[] objects, flattened and including nested/grouped rows. Each TableRow contains the raw data in the row property plus metadata like depth, position, and rowPath. Perfect for analytics, batch operations, or custom exports.
1// Calculate total revenue from all rows2const allRows = tableRef.current?.getAllRows();3const totalRevenue = allRows?.reduce((sum, tableRow) =>4 sum + (tableRow.row.revenue || 0), 05);67// Access row metadata8allRows?.forEach(tableRow => {9 console.log(`Depth: ${tableRow.depth}, Position: ${tableRow.position}`);10 console.log("Data:", tableRow.row);11});1213// Export raw data to custom format14const allRows = tableRef.current?.getAllRows();15const rawData = allRows?.map(tableRow => tableRow.row);16const jsonData = JSON.stringify(rawData, null, 2);17downloadFile(jsonData, "data.json");
getHeaders() - Access Column Configuration
Returns the table's current header/column definitions. Useful for dynamic table manipulation or building custom UI controls.
1// Get all column names2const headers = tableRef.current?.getHeaders();3const columnNames = headers?.map(h => h.label);4console.log("Columns:", columnNames);56// Validate configuration7const sortableColumns = headers?.filter(h => h.isSortable);8console.log(`${sortableColumns.length} sortable columns`);