This is a migrated thread and some comments may be shown as answers.

Excel export with dynamic names

4 Answers 377 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Joe
Top achievements
Rank 1
Joe asked on 17 Jan 2018, 06:44 PM
Is there a way to specify a dynamic name for the export to Excel function?  The FileName() method takes a string, but I want the name to reflect certain filter conditions within the grid, and need to change the name of the exported file.  Ideally, I'd like to be able to call a javascript function that would build the name dynamically.  Any way to accomplish this?

4 Answers, 1 is accepted

Sort by
0
Stefan
Telerik team
answered on 19 Jan 2018, 08:54 AM
Hello, Joe,

The desired result can be achieved on the excelExport event by programmatically setting a new value of the exported workbook name:

https://docs.telerik.com/kendo-ui/api/javascript/ui/grid/events/excelexport#excelexport

https://dojo.telerik.com/oDeya

I hope this is helpful.

Regards,
Stefan
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Joe
Top achievements
Rank 1
answered on 19 Jan 2018, 03:28 PM
Thanks.  Now I just have to work out how this works for the MVC component.
0
Joe
Top achievements
Rank 1
answered on 19 Jan 2018, 03:47 PM

I just don't know what I'm supposed to do with this.  After my grid Reads it's data (AutoBind = false), I call this little segment:

$("#licenseGrid").data("kendoGrid").bind("excelExport", function(e) {
          e.workbook.filename = colorModel.get("SelectedPeo") + "_LicenseRegistration.xlsx";
});

 

And when my grid loads, I click the excel button, it's not coming up with this name at all, it's just coming up as plain Export.xlsx.  So how do I use this with MVC?  

0
Alex Hajigeorgieva
Telerik team
answered on 23 Jan 2018, 09:24 AM
Hi, Joe,

The approach for adding an excelExport event handler to an already initialized grid is correct. The issue comes from the casing of the filename property.

Change it to camel case as below:

$("#licenseGrid").data("kendoGrid").bind("excelExport", function(e) {
  e.workbook.fileName = colorModel.get("SelectedPeo") + "_LicenseRegistration.xlsx";
});

Alternatively, you may use the Razor syntax to attach the vent handler in the configuration of the grid. 

@(Html.Kendo().Grid<ProjectName.Models.ProductViewModel>()
  .Events(events => events
   .ExcelExport("onExcelExport")
 
<script>
function onExcelExport(e){
   e.workbook.fileName = colorModel.get("SelectedPeo") + "_LicenseRegistration.xlsx";
}
</script>

Kind Regards,
Alex Hajigeorgieva
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
Grid
Asked by
Joe
Top achievements
Rank 1
Answers by
Stefan
Telerik team
Joe
Top achievements
Rank 1
Alex Hajigeorgieva
Telerik team
Share this question
or