Grid CSV Export
You can export the grid to CSV with a click of a button. The current filter, sort, page, grouping and column order are applied to the .csv document.
When you click the Export button, your browser will receive the resulting file.
Make sure to get familiar with all the general export documentation first.
In This Article
Basics
To enable the CSV export in the Grid:
Add the Export Tool
Add the GridToolBarCsvExportTool inside the <GridToolBar>:
<GridToolBar>
<GridToolBarCsvExportTool>
Export to CSV
</GridToolBarCsvExportTool>
</GridToolBar>
If you have a custom Toolbar, add a command button with the CsvExport command name inside a templated Grid Toolbar(<GridToolBarTemplate>).
Configure the Export Settings
To configure the CSV export settings, add the GridCsvExport tag under the GridExport tag. You may set the following options:
| Parameter | Type and Default Value | Description |
|---|---|---|
FileName | string | The name of the file. The grid will add the .csv extension for you. |
AllPages | bool | Whether to export the current page only, or the entire data from the data source. |
For further customizations, use the GridExcelExport tag to subscribe to the Grid export events.
Export the Grid to CSV
Programmatic Export
You can programmatically invoke the export feature of the Grid, by using the following methods exposed on the @ref of the Grid:
| Method | Type | Description |
|---|---|---|
SaveAsCsvFileAsync | ValueTask | Sends the exported CSV file to the browser for download. You can pass GridCsvExportOptions to customize the export. |
ExportToCsvAsync | Task<MemoryStream> | Returns the exported data as a MemoryStream. The stream itself is finalized, so that the resource does not leak. To read and work with the stream, clone its available binary data to a new MemoryStream instance. You can pass GridCsvExportOptions to customize the export. |
When exporting programmatically with a GridCsvExportOptions argument:
- The
ColumnsandDataproperties ofGridCsvExportOptionsare required. - Multi-column headers are not supported.
Invoke the export function from code
Customization
To customize the exported file, handle the OnBeforeExport or OnAfterExport events the Grid exposes.
The component allows you to control the data set that will be exported. It also provides built-in customization options for the columns, such as Width, Title, and more.
For more advanced customizations (such as formatting the numbers and dates, or changing the default comma delimiter) the Grid lets you get the MemoryStream of the file. Thus, you can customize it using the SpreadProcessing or the SpreadStreamProcessing libraries that are available with your license.
Read more about how to customize the exported file...