New to Telerik UI for ASP.NET CoreStart a free 30-day trial

Customizing the Excel Export Filename of the Grid by Adding Current Date and Time

Environment

ProductGrid for Progress® Telerik® UI for ASP.NET Core

Description

How can I add the current date and time to the Excel export filename of the Grid when working with the Telerik UI for ASP.NET Core components?

Solution

Use the excelExport event which has the workbook in its event data to rename it.

With the help of the kendo.toString() method or another way to format the date, concatenate the date to the filename.

Index.cshtml
@(Html.Kendo().Grid<GridExportCustomName.Models.OrderViewModel>()
    .Name("grid")
    .Columns(columns =>
    {
        columns.Bound(e => e.OrderID);
        columns.Bound(e => e.Freight);
    })
    .ToolBar(t => 
    {
        t.Excel();
    })
    .Events(ev=>ev.ExcelExport("onExcelExport"))
    .DataSource(dataSource => dataSource
        .Custom()
        .Type("odata")
        .Transport(transport =>
           transport.Read(read => read.Url("https://demos.telerik.com/kendo-ui/service/Northwind.svc/Orders"))
        )
        .PageSize(10)
    )

)

More ASP.NET Core Grid Resources

See Also