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

Set excel filename dynamically

2 Answers 1859 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Danny
Top achievements
Rank 2
Danny asked on 15 Mar 2017, 04:34 PM

I have a grid with the export to excel functionality turned on:

 

@(Html.Kendo().Grid<IncompleteCOATests>()
                          .Name("IncompleteCOATestsGrid")
                          .HtmlAttributes(new { style = "width: 980px" })
                          .Columns(columns =>
                          {
                              columns.Bound(c => c.UnitId).Title("Unit Id");
                              columns.Bound(c => c.ParentId).Title("Parent Id");
                              columns.Bound(c => c.Qparam).Title("QParam");
                              columns.Bound(c => c.TestAlias).Title("Test Name");                                                    
                          })
                          .ToolBar(tools => tools.Excel())
                          .Excel(excel => excel
                                    .FileName("Missing Tests.xls")
                                    .Filterable(true)
                                    .ProxyURL(Url.Action("Excel_Export_Save", "Grid")))
                          .NoRecords(x => x.Template(@ResourceMessages.NoRecordFoundForConsignee))
                          .AutoBind(false)
                          .Pageable(pageable => pageable
                              .Enabled(false)
                              .Refresh(true)
                              .PageSizes(false))
                          .DataSource(dataSource => dataSource
                              .Ajax()
                              .Events(events => events.Error("GlobalModule.onError"))
                              .Read(read => read.Url(Url.HttpRouteUrl("ActionApi", new { controller = "PoPsApi", action = "GetIncompleteCOATests" })).Type(HttpVerbs.Get).Data("IncompleteCoAsModule.getLoadOrderItem")))
 
)

 

It databinds on a client-side button press

export function showMissingTests(e) {
    $('#IncompleteCOATestsGrid').data("kendoGrid").dataSource.read();
}

 

Is it possible to set the excel.Filename property client side? 

When/how in the page lifecyle would I do that? 

 

 

 

2 Answers, 1 is accepted

Sort by
0
Accepted
Alex Hajigeorgieva
Telerik team
answered on 17 Mar 2017, 10:42 AM
Hi Danny,

To set the name of the Kendo UI Grid Excel export dynamically, add an event handler to the excelExport event. The generated workbook is available for modifications, including the filename at this point:

http://docs.telerik.com/kendo-ui/api/javascript/ui/grid#events-excelExport

The API reference above includes a runnable sample which shows how to change the name but I extended it a little for more convenience at:

http://dojo.telerik.com/AJOXo

Kind Regards,
Alex Hajigeorgieva
Telerik by Progress
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Danny
Top achievements
Rank 2
answered on 17 Mar 2017, 02:30 PM
@(Html.Kendo().Grid<IncompleteCOATests>()
                          .Name("IncompleteCOATestsGrid")
                          .HtmlAttributes(new { style = "width: 980px" })
                          .Columns(columns =>
                          {
                              columns.Bound(c => c.UnitId).Title("Unit Id");
                              columns.Bound(c => c.ParentId).Title("Parent Id");
                              columns.Bound(c => c.Qparam).Title("QParam");
                              columns.Bound(c => c.TestAlias).Title("Test Name");
                          })
                          .ToolBar(tools => tools.Excel())
                          .ToolBar(tools => tools.Custom().Text("<span class='glyphicon glyphicon-arrow-left'></span> Back To Incomplete CoAs").HtmlAttributes(new { id = "backToResultsBtn"}))
                          .Excel(excel => excel
                                    .Filterable(true)
                                    .ProxyURL(Url.Action("Excel_Export_Save", "Grid")))
                          .Events(events => events.ExcelExport("IncompleteCoAsModule.incompleteCOATestsGridOnExcelExport"))
                          .NoRecords(x => x.Template(@ResourceMessages.NoRecordFoundForConsignee))
                          .AutoBind(false)
                          .Pageable(pageable => pageable
                              .Enabled(false)
                              .Refresh(true)
                              .PageSizes(false))
                          .DataSource(dataSource => dataSource
                              .Ajax()
                              .Events(events => events.Error("GlobalModule.onError"))
                              .Read(read => read.Url(Url.HttpRouteUrl("ActionApi", new { controller = "PoPsApi", action = "GetIncompleteCOATests" })).Type(HttpVerbs.Get).Data("IncompleteCoAsModule.getLoadOrderItem")))
 
)

 

Added client events: 

export function incompleteCOATestsGridOnExcelExport(e) {
        e.workbook.fileName = orderId.trim() + "-" + orderItemNumber + " Load ID: " + loadId + " Missing Tests ";
    }

 

This got it done, thanks for the quick reply!

 

 

 

Tags
Grid
Asked by
Danny
Top achievements
Rank 2
Answers by
Alex Hajigeorgieva
Telerik team
Danny
Top achievements
Rank 2
Share this question
or