You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
*`bool` fields are exported as `TRUE` or `FALSE` strings, because there is no boolean data type in Excel and these string values are the most common ones used in data and macros.
3
+
4
+
* Date and number formats are exported with the following format: `mm/dd/yyyy hh:mm:ss` plus the current app culture AM/PM specifier for dates, and `Convert.ToDouble(value)` for numbers (which uses the current thread culture). The Excel date formats are different than .NET date formats and Excel may not always recognize the column as dates, for example, if the entire date format from the .NET culture is used.
5
+
6
+
* Templates are not exported, because there is no provision in the framework for getting them at runtime. If a column, header or group header/footer has a template or aggregates, it will be ignored. The headers will be the `Title` of the column, the data is the data from the `Field`. If you need additional information, see if you can add it in e Field in the model, or create your own excel file (see example <ahref="https://feedback.telerik.com/blazor/1485764-customize-the-excel-file-before-it-gets-to-the-client"target="_blank">here</a>).
7
+
8
+
* Only columns that have a `Field` set are exported.
9
+
10
+
* If you are using the `OnRead` event, only the current page of data will be exported, because that's all the grid has at the time of the export action.
11
+
12
+
* With Server-side Blazor, the file may become larger than the default SignalR connection limit, and this can disconnect the client and result in an error. Generally, this requires quite a lot of data to happen, but you may need to increase the size limit of the connection in the `ConfigureServices` method of your `Startup.cs` file, for example:
13
+
14
+
**C#**
15
+
16
+
services.AddServerSideBlazor().AddHubOptions(o =>
17
+
{
18
+
o.MaximumReceiveMessageSize = 1024 * 1024; // 1MB
19
+
});
20
+
21
+
* With Client-side Blazor (WebAssembly), all the code runs in the browser and, at the time of writing, is considerably slower than server-side Blazor, and it only has one actual thread. This means that while the file is being generated, the UI will be unresponsive, so you may want to show a loading sign to the user through the `OnClick` handler of the command button, something like:
22
+
23
+
**Component**
24
+
25
+
@* Exporting a lot of rows can be slow in a WebAssembly app more so than in a server-side app, and it blocks the UI *@
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.
14
+
15
+
When you click the Export button, your browser will receive the resulting file.
16
+
17
+
18
+
## Basics
19
+
20
+
To enable the grid CSV Export, add a [command button]({%slug components/grid/columns/command%}) with the `CsvExport` command name to the [toolbar]({%slug components/grid/features/toolbar%}).
21
+
22
+
````
23
+
<GridToolBar>
24
+
<GridCommandButton Command="CsvExport" Icon="@IconName.FileCsv">Export to CSV</GridCommandButton>
25
+
</GridToolBar>
26
+
````
27
+
28
+
Optionally, you can also set the `GridCsvExport` tag settings under the `GridExport` tag to choose:
29
+
30
+
*`FileName` - the name of the file. The grid will add the `.csv` extension for you.
31
+
*`AllPages` - whether to export the current page only, or the entire data from the data source.
32
+
33
+
>caption Export the Grid to CSV - Example
34
+
35
+
````CSHTML
36
+
@* You can sort, group, filter, page the grid, reorder its columns, and you can click the
GridData = Enumerable.Range(1, 100).Select(x => new SampleData
68
+
{
69
+
ProductId = x,
70
+
ProductName = $"Product {x}",
71
+
UnitsInStock = x * 2,
72
+
Price = 3.14159m * x,
73
+
Discontinued = x % 4 == 0,
74
+
FirstReleaseDate = DateTime.Now.AddDays(-x)
75
+
}).ToList();
76
+
}
77
+
78
+
public class SampleData
79
+
{
80
+
public int ProductId { get; set; }
81
+
public string ProductName { get; set; }
82
+
public int UnitsInStock { get; set; }
83
+
public decimal Price { get; set; }
84
+
public bool Discontinued { get; set; }
85
+
public DateTime FirstReleaseDate { get; set; }
86
+
}
87
+
}
88
+
````
89
+
90
+
## Notes
91
+
92
+
The CSV export has the following specifics:
93
+
94
+
* Column widths are not applied because a CSV document does not have such a concept. You can use any units in the grid itself, they will not be reflected in the exported document. If you need to add such structure, consider [exporting to an Excel file]({%slug grid-export-excel%}).
Copy file name to clipboardExpand all lines: components/grid/export/excel.md
+1-76Lines changed: 1 addition & 76 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -91,84 +91,9 @@ Optionally, you can also set the `GridExcelExport` tag settings under the `GridE
91
91
92
92
The Excel export has the following specifics:
93
93
94
-
*`bool` fields are exported as `TRUE` or `FALSE` strings, because there is no boolean data type in Excel and these string values are the most common ones used in data and macros.
95
-
96
-
* Date and number formats are exported with the following format: `mm/dd/yyyy hh:mm:ss` plus the current app culture AM/PM specifier for dates, and `Convert.ToDouble(value)` for numbers (which uses the current thread culture). The Excel date formats are different than .NET date formats and Excel may not always recognize the column as dates, for example, if the entire date format from the .NET culture is used.
97
-
98
-
* Templates are not exported, because there is no provision in the framework for getting them at runtime. If a column, header or group header/footer has a template or aggregates, it will be ignored. The headers will be the `Title` of the column, the data is the data from the `Field`. If you need additional information, see if you can add it in e Field in the model, or create your own excel file (see example <ahref="https://feedback.telerik.com/blazor/1485764-customize-the-excel-file-before-it-gets-to-the-client"target="_blank">here</a>).
99
-
100
-
* Only columns that have a `Field` set are exported.
101
-
102
94
* Excel does not understand units different than `px` for the column `Width`, and if you use them (such as `rem` or `%`), it will fail to parse them and will render a collapsed (hidden) column with zero width.
103
95
104
-
* If you are using the `OnRead` event, only the current page of data will be exported, because that's all the grid has at the time of the export action.
105
-
106
-
* With Server-side Blazor, the file may become larger than the default SignalR connection limit, and this can disconnect the client and result in an error. Generally, this requires quite a lot of data to happen, but you may need to increase the size limit of the connection in the `ConfigureServices` method of your `Startup.cs` file, for example:
107
-
108
-
**C#**
109
-
110
-
services.AddServerSideBlazor().AddHubOptions(o =>
111
-
{
112
-
o.MaximumReceiveMessageSize = 1024 * 1024; // 1MB
113
-
});
114
-
115
-
* With Client-side Blazor (WebAssembly), all the code runs in the browser and, at the time of writing, is considerably slower than server-side Blazor, and it only has one actual thread. This means that while the file is being generated, the UI will be unresponsive, so you may want to show a loading sign to the user through the `OnClick` handler of the command button, something like:
116
-
117
-
**Component**
118
-
119
-
@* Exporting a lot of rows can be slow in a WebAssembly app more so than in a server-side app, and it blocks the UI *@
0 commit comments