Angular Grid: 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) | Downloads a CSV export of the grid's data. |
getDataAsCsv(params) | Similar to exportDataAsCsv , except returns the result as a string rather than download it. |
exportDataAsExcel(params) | Downloads an Excel export of the grid's data. |
getDataAsExcel(params) | Similar to exportDataAsExcel , except instead of downloading a file, it will return a string when exportMode='xml' or a Blob when exportMode='xlsx' . |
Each of these methods takes an optional params
object, which has the following properties for all exports:
allColumns | If true , all columns will be exported in the order they appear in columnDefs . Otherwise only the columns currently showing in the grid, and in that order, are exported.Default: false |
columnGroups | Set to true to include header column groupings.Default: false |
columnKeys | Provide a list (an array) of column keys if you want to export specific columns. |
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.
|
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.
|
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 .
|
processHeaderCallback | A callback function invoked once per column. Return a string to be displayed in the column header.
|
processRowGroupCallback | A callback function invoked once per row group. Return a string to be displayed in the group cell.
|
shouldRowBeSkipped | A callback function that will be invoked once per row in the grid. Return true to omit the row from the export.
|
skipFooters | Set to true to skip footers only if grouping. No impact if not grouping or if not using footers in grouping.Default: false |
skipGroups | Set to true to skip row group headers and footers if grouping rows. No impact if not grouping rows.Default: false |
skipHeader | Set to true if you don't want the first line to be the column header names.Default: false |
skipPinnedTop | Set to true to suppress exporting rows pinned to the top of the grid.Default: false |
skipPinnedBottom | Set to true to suppress exporting rows pinned to the bottom of the grid.Default: false |
Additional properties are included depending on the export type; please see the pages specific to each export type for more details.
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:
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;
}
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 iOS
It is not possible to download files directly from JavaScript to an iPad / iPhone. 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 / iPhone. If you do want to download on iPad / iPhone, 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.