Export

This page covers the export options that are common to both CSV and Excel.

The grid provides APIs to export data to CSV and Excel. You can download a file to the user's computer or generate a string to be uploaded to a server. For more detail on the specific options for each format see:

Selecting Data to Export

Data can be exported using one of the following API methods:

  • exportDataAsCsv(params): download a CSV file to the user's computer.
  • exportDataAsExcel(params): download an Excel file to the user's computer.
  • getDataAsCsv(params): return a CSV string.
  • getDataAsExcel(params): return an Excel XML string. This forces exportMode to 'xml'.

Each of these methods takes an optional params object:

allColumns If true, all columns will be exported in the order they appear in columnDefs. Otherwise only the columns currently showing the in grid, and in that order, are exported.
columnGroups Set to true to include header column groupings.
columnKeys Provide a list (an array) of column keys if you want to export specific columns.
columnSeparator The column separator. Defaults to comma.
customHeader Content to put at the top of the file export. A 2D array of ExcelCell objects, see Custom Headers and Footers below. Alternatively, if you're exporting to CSV only, you can pass a multi-line string that is simply appended to the top of the file content.
customFooter Same as customHeader, but for the bottom of the exported file.
fileName String to use as the file name. If missing, the file name 'export.csv' will be used.
getCustomContentBelowRow A callback function to return styled content to be inserted below a row in the export. The callback params has the following attributes: node, api, columnApi, context.
onlySelected Only export selected rows.
onlySelectedAllPages Only export selected rows including other pages (only makes sense when using pagination).
processCellCallback A callback function invoked once per cell in the grid. Return a string value to be displayed in the export. Useful e.g. for formatting date values. The callback params has the following attributes: value, node, column, api, columnApi, context.
processGroupHeaderCallback A callback function invoked once per column group. Return a string to be displayed in the column group header. Note that column groups are not exported by default, you must pass columnGroups=true. The callback params has the following attributes: columnGroup, api, columnApi, context.
processHeaderCallback A callback function invoked once per column. Return a string to be displayed in the column header. The callback params has the following attributes: column, api, columnApi, context.
processRowGroupCallback A callback function invoked once per row group. Return a string to be displayed in the group cell. The callback params has the following attributes: node, api, columnApi, context.
shouldRowBeSkipped A callback function that will be invoked once per row in the grid - return true omit the row from the export. The callback is passed an object with the following attributes: node, api, context.
skipFooters Set to true to skip footers only if grouping. No impact if not grouping or if not using footers in grouping.
skipGroups Set to true to skip row group headers and footers if grouping rows. No impact if not grouping rows.
skipHeader Set to true if you don't want to first line to be the column header names.
skipPinnedTop Set to true to suppress exporting rows pinned to the top of the grid.
skipPinnedBottom Set to true to suppress exporting rows pinned to the bottom of the grid.
suppressQuotes Set to true to not use double quotes between values.

Example: Selecting Data to Export

This example demonstrates the options that control what data to export. Note that:

  • Filtered rows are not included in the export.
  • The sort order is maintained in the export.
  • The order of the columns is maintained in the export.
  • Only visible columns are export.
  • Value getters are used to work out the value to export (the 'Name Length' col in the example below uses a value getter return the number of characters in the name)
  • Aggregated values are exported.
  • For groups, the first exported value (column) will always have the group key.
  • Heading groups are exported as part of the csv.

What Gets Exported

The same data that is in the grid gets exported, but none of the GUI representation of the data will be. What this means is:

  • The raw values, and not the result of cell renderer, will get used, meaning:
    • Cell Renderers will NOT be used.
    • Value Getters will be used.
    • Cell Formatters will NOT be used (use processCellCallback instead).
  • Cell styles are not exported by default. CSV does not allow styling. For details on styling the Excel export, see Excel Export.
  • If row grouping:
    • all data will be exported regardless of whether groups are open in the UI.
    • by default, group names will be in the format "-> Parent Name -> Child Name" (use processRowGroupCallback to change this)
    • row group footers (groupIncludeFooter=true) will NOT be exported - this is a GUI addition that happens for displaying the data in the grid.
If you want to disable export, you can set the properties suppressCsvExport = true and suppressExcelExport = true in your gridOptions.

Example: Formatting Exported Data

This example demonstrates the options that modify the exported data:

  • Aggregated values are exported.
  • For groups, the first exported value (column) will always have the group key.
  • Heading groups are exported as part of the csv.

Custom Headers and Footers

customHeader and customFooter both take a 2D array of ExcelCell objects:

export interface ExcelCell { data: ExcelData; // Optional style to apply styleId?: string; // Optional The number of _additional_ cells to span across, so // 1 means that the cell will span 2 columns mergeAcross?: number; } export interface ExcelData { // Excel data type. Case sensitive. type: 'String' | 'Number' | 'Boolean' | 'DateTime' | 'Error'; value: string | null; }

See the styles section of the Excel Export page for more information how the styleId property is interpreted. The CSV exporter will ignore style information.

The CSV exporter can accept a multi-line string for customHeader and customFooter, see the CSV Export page for more information.

Export on an iPad

It is not possible to download files directly from JavaScript to an iPad. This is a restriction of iOS and not something wrong with ag-Grid. For this reason, the download links in the context menu are removed when running on iPad. If you do want to download on iPad, then it is recommended you use the api function getDataAsCsv() to get the export data and then send this to the server to allow building an endpoint for doing the download.