diff --git a/components/grid/export/csv.md b/components/grid/export/csv.md index 676526beb..39d03f350 100644 --- a/components/grid/export/csv.md +++ b/components/grid/export/csv.md @@ -105,10 +105,8 @@ You can programmatically invoke the export feature of the Grid, by using the fol | Method | Type | Description | | --- | --- | --- | -| `SaveAsCsvFileAsync` | `ValueTask` | Sends the exported CSV file to the browser for download. | -| `ExportToCsvAsync` | `Task` | 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. | - ->note The same methods are exposed for exporting an [Excel file](slug:grid-export-excel#programmatic-export). +| `SaveAsCsvFileAsync` | `ValueTask` | Sends the exported CSV file to the browser for download. You can pass [`GridCsvExportOptions`](slug:Telerik.Blazor.Components.Grid.GridCsvExportOptionsDescriptor) to customize the export. | +| `ExportToCsvAsync` | `Task` | 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`](slug:Telerik.Blazor.Components.Grid.GridCsvExportOptionsDescriptor) to customize the export. | >caption Invoke the export function from code @@ -116,14 +114,18 @@ You can programmatically invoke the export feature of the Grid, by using the fol @* Send the exported file for download and get the exported data as a memory stream *@ @using System.IO +@using Telerik.Blazor.Components.Grid; Download the CSV file Get the Exported Data as a MemoryStream +Download CSV with Options +Get CSV Data with Options @@ -138,42 +140,66 @@ You can programmatically invoke the export feature of the Grid, by using the fol - - - - - - + + + + + + @code { private TelerikGrid GridRef { get; set; } - - private MemoryStream exportedCSVStream { get; set; } - + private MemoryStream exportedCsvStream { get; set; } private List GridData { get; set; } - private bool ExportAllPages { get; set; } private async Task GetTheDataAsAStream() { - MemoryStream finalizedStream = await GridRef.ExportToCsvAsync(); + var exportStream = await GridRef.ExportToCsvAsync(); + exportedCsvStream = new MemoryStream(exportStream.ToArray()); + } + + private async Task SaveAsCsvWithOptions() + { + await GridRef.SaveAsCsvFileAsync(new GridCsvExportOptions() + { + FileName = "custom-export", + Data = GridData.Take(10).ToList(), + Columns = new List() + { + new GridCsvExportColumn() { Field = nameof(SampleData.ProductId) }, + new GridCsvExportColumn() { Field = nameof(SampleData.ProductName) } + } + }); + } - exportedCSVStream = new MemoryStream(finalizedStream.ToArray()); + private async Task ExportToCsvWithOptions() + { + var exportStream = await GridRef.ExportToCsvAsync(new GridCsvExportOptions() + { + Data = GridData.Take(10).ToList(), + Columns = new List() + { + new GridCsvExportColumn() { Field = nameof(SampleData.ProductId) }, + new GridCsvExportColumn() { Field = nameof(SampleData.ProductName) } + } + }); + exportedCsvStream = new MemoryStream(exportStream.ToArray()); } protected override void OnInitialized() { GridData = Enumerable.Range(1, 100).Select(x => new SampleData - { - ProductId = x, - ProductName = $"Product {x}", - UnitsInStock = x * 2, - Price = 3.14159m * x, - Discontinued = x % 4 == 0, - FirstReleaseDate = DateTime.Now.AddDays(-x) - }).ToList(); + { + ProductId = x, + ProductName = $"Product {x}", + UnitsInStock = x * 2, + Price = 3.14159m * x, + Discontinued = x % 4 == 0, + FirstReleaseDate = DateTime.Now.AddDays(-x) + }).ToList(); } public class SampleData diff --git a/components/grid/export/excel.md b/components/grid/export/excel.md index 01db7bcbf..2e14345f0 100644 --- a/components/grid/export/excel.md +++ b/components/grid/export/excel.md @@ -105,10 +105,8 @@ You can programmatically invoke the export feature of the Grid, by using the fol | Method | Type | Description | | --- | --- | --- | -| `SaveAsExcelFileAsync` | `ValueTask` | Sends the exported excel file to the browser for download. | -| `ExportToExcelAsync` | `Task` | 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. | - ->note The same methods are exposed for exporting a [CSV file](slug:grid-export-csv#programmatic-export). +| `SaveAsExcelFileAsync` | `ValueTask` | Sends the exported excel file to the browser for download. You can pass [`GridExcelExportOptions`](slug:Telerik.Blazor.Components.Grid.GridExcelExportOptionsDescriptor) to customize the export. | +| `ExportToExcelAsync` | `Task` | 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 [`GridExcelExportOptions`](slug:Telerik.Blazor.Components.Grid.GridExcelExportOptionsDescriptor) to customize the export. | >caption Invoke the export function from code @@ -116,9 +114,12 @@ You can programmatically invoke the export feature of the Grid, by using the fol @* Send the exported file for download and get the exported data as a memory stream *@ @using System.IO +@using Telerik.Blazor.Components.Grid; Download the excel file Get the Exported Data as a MemoryStream +Download Excel with Options +Get Excel Data with Options GridRef { get; set; } - private MemoryStream exportedExcelStream { get; set; } - private List GridData { get; set; } - private bool ExportAllPages { get; set; } private async Task GetTheDataAsAStream() { MemoryStream finalizedStream = await GridRef.ExportToExcelAsync(); - exportedExcelStream = new MemoryStream(finalizedStream.ToArray()); } + private async Task SaveAsExcelWithOptions() + { + await GridRef.SaveAsExcelFileAsync(new GridExcelExportOptions() + { + FileName = "custom-export", + Data = GridData.Take(10).ToList(), + Columns = new List() + { + new GridExcelExportColumn() { Field = nameof(SampleData.ProductId), Width = "100px" }, + new GridExcelExportColumn() { Field = nameof(SampleData.ProductName), Width = "300px" } + } + }); + } + + private async Task ExportToExcelWithOptions() + { + var exportStream = await GridRef.ExportToExcelAsync(new GridExcelExportOptions() + { + Data = GridData.Take(10).ToList(), + Columns = new List() + { + new GridExcelExportColumn() { Field = nameof(SampleData.ProductId), Width = "100px" }, + new GridExcelExportColumn() { Field = nameof(SampleData.ProductName), Width = "300px" } + } + }); + + exportedExcelStream = new MemoryStream(exportStream.ToArray()); + } + protected override void OnInitialized() { GridData = Enumerable.Range(1, 100).Select(x => new SampleData - { - ProductId = x, - ProductName = $"Product {x}", - UnitsInStock = x * 2, - Price = 3.14159m * x, - Discontinued = x % 4 == 0, - FirstReleaseDate = DateTime.Now.AddDays(-x) - }).ToList(); + { + ProductId = x, + ProductName = $"Product {x}", + UnitsInStock = x * 2, + Price = 3.14159m * x, + Discontinued = x % 4 == 0, + FirstReleaseDate = DateTime.Now.AddDays(-x) + }).ToList(); } public class SampleData