ExcelExport in Blazor UI Grid

1 Answer 415 Views
Grid
Jayakumar
Top achievements
Rank 1
Jayakumar asked on 30 Jun 2023, 12:28 AM

Hello,

   I want to change the filename dynamically after the initial loading of a grid in a razor page, So lets say I refresh a grid after a search  and export to a file telerik_101123.xlsx.  (10:11:23 being the current time). Then 2 min later I refresh the grid again and export it to telerik_101323.xlsx. How can I do that

Deasun
Top achievements
Rank 3
Bronze
Bronze
Bronze
commented on 03 Jul 2023, 11:58 AM

This is the grid tag you need to set:

<GridExport>
                            <GridExcelExport FileName="@msExportFileName" AllPages="@Revenue_ExportAllPages" OnBeforeExport="@Revenue_OnBeforeExcelExport" />
                    </GridExport>

This is the variable you need for the name: msExportFileName

In code behind:

string msExportFileName = "Rpt_";

where you set the name is the important thing.

msExportFileName = "Rpt_" + RptFilters.strFilter01.Replace("/", "") + "_" + msRevGrid_Lvl1Pick + "_" + strItemIs;

{ you'd set that with your naming convention. }

try to do it somewhere before OnBeforeExcelExport gets called. Doing it in there wont work.

So under a DDL or button object. Or in my case above where I have sub grids within main grid I do it on the OnRowExpand() & OnRowCollapse()

 

Hope that helps.

Deasun.

 

 

1 Answer, 1 is accepted

Sort by
0
Yanislav
Telerik team
answered on 04 Jul 2023, 10:01 AM

Hello Jayakumar,

The goal seems achievable. Allow me to offer the following steps to accomplish it:

  1. Create a custom button.
  2. In the OnClick event of the button, modify the file name and export the Grid using the SaveAsExcelFileAsync method.

Here's a REPL example that demonstrates this approach: https://blazorrepl.telerik.com/mHOLOebk00SDPXGU53
I hope you find this information helpful.

Regards,
Yanislav
Progress Telerik

As of R2 2023, the default icon type will be SVG instead of Font. See this blogpost for more information.
Tags
Grid
Asked by
Jayakumar
Top achievements
Rank 1
Answers by
Yanislav
Telerik team
Share this question
or