Completed
Last Updated: 09 Apr 2022 11:48 by ADMIN
Release 3.0.0
License
Created on: 28 May 2020 13:47
Category: Grid
Type: Feature Request
53
Include all pages in Excel export should work with OnRead

With OnRead, AllPages cannot be exported because the grid Data only has the current page: https://docs.telerik.com/blazor-ui/components/grid/export/excel#notes:

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.

 

I load my data via "OnRead", because i need to implement pagination by myself, and I would like the export option to work with that too.

7 comments
ADMIN
Marin Bratanov
Posted on: 09 Apr 2022 11:48

Hi Adam,

When AllPages=true and OnRead is used, an OnRead call will be made with PageSize=0.

You can find out more about that and other behavior of the excel export here: https://docs.telerik.com/blazor-ui/components/grid/export/excel#notes

Regards,
Marin Bratanov
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Adam
Posted on: 06 Apr 2022 18:48
I'm confused. This is marked completed for 3.0.0. Is an official updated added to the grid export to handle getting data for all pages (when all pages are requested) when server-side paging is being used or do we use the workaround in the linked feedback KB?
Matt
Posted on: 29 Jul 2021 16:03

Here's my workaround for this. If somebody really needs a full example I'm sure I can whip up a quick razor page, or maybe Marin can take this and build a full example. But this should be enough for anybody to work off of.

First thing I do is get the datagrid's current state.  Then I build a DataSourceRequest off of that.  For the page size, I set it to the total number of records that exist.  I can then send that request off to the same service that I am using to populate the data grid.  I can then build my own excel document using the library of my choice, and I'm sure this can easily be done with Telerik Document Processing library.  I'm using SpreadSheetLight (https://spreadsheetlight.com/)

var state = this.dataGridRef.GetState();
DataSourceRequest req = new();
req.Filters = new List<IFilterDescriptor>(state.FilterDescriptors.OfType<IFilterDescriptor>());
req.Sorts = new List<SortDescriptor>(state.SortDescriptors);
req.PageSize = this.TotalRecords;

DataSourceResult dsr = await this.dataService.GetSomeData(req);
var dataToExport = dsr.Data as IEnumerable<SomeDataModel>();

// Build your excel export using the library of your choice
SLDocument excelDoc = new();
int row = 1;
foreach(var record in dataToExport)
{
    excelDoc.SetCellValue(row, 1, record.Value1);
    excelDoc.SetCellValue(row, 2, record.Value2);
    row++;
}

// You need to then convert the excel to a Base64String needed to download the file
// The SLDocument.SaveAs method accepts a stream as a destination so I'm writing to a memory stream instead of to a file

string b64ExportData;
using(MemoryStream outStream = new())
{
    excelDoc.SaveAs(outStream);
    var exportRaw = outStream.ToArray();
    b64ExportData = Convert.ToBase64String(exportRaw);
}

// Download the extract once you have the base 64 string. 
// I'm using this javascript function found here which I found here:
//  https://github.com/telerik/blazor-ui/blob/master/grid/pdf-export-server/ServerSideSample/wwwroot/saveFile.js 
await this.JSRuntine.InvokeVoidAsync("saveFile", b64ExportData, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", "DataGridExport.xlsx");

 

ADMIN
Marin Bratanov
Posted on: 27 Jul 2021 05:12

Hello Meindert,

The only workaround I can offer is generating the export entirely in the application code, you can find a sample here: https://feedback.telerik.com/blazor/1485764-customize-the-excel-file-before-it-gets-to-the-client

Regards,
Marin Bratanov
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Meindert
Posted on: 26 Jul 2021 10:17
Would be functional if this item is solved/implemented. Is there a workaround?
Ian
Posted on: 04 Jun 2021 13:03

I agree, this would be really useful.

Also useful if you could set a MAX number of records, this could ensure the export is not too big.

Umakant
Posted on: 21 May 2021 07:01
Its a very useful feature. Request Telerik to work on it.