Reputation: 79
I am using Kendo UI and exporting grid data to excel, I know the process and it works fine for me. Now I want the excel file name to be a date like "12-12-2014.xlsx" although I can get the date value from drop down using Javascript , but I can't send this date value to my Kendo UI Grid. Here is the code , can any one help me please or any other suggestions?
<script type="text/javascript">
var selectedDate ="";
$("#startDate").change(function (e) {
selectedDate = $(this).val();
var sd = selectedDate.split('/');
selectedDate = sd[0] + "-" + sd[1] + "-" + sd[2];
// selectedDate must be the excel file name
});
</script>
Kendo UI grid :
@(Html.Kendo().Grid<Futuresteps.Media.Models.PrintMedia>()
.Name("grid")
.Columns(columns =>
{
// some data
})
.Excel(excel => excel
.FileName(selectedDate+".xlsx")
.Filterable(true)
.ProxyURL(Url.Action("Excel_Export_Save", "PrintMedias"))
)
Upvotes: 1
Views: 1229
Reputation: 40887
Since the date can change you should compute the date when about to export the file to Excel and not in creation time as you do in:
.Excel(excel => excel
.FileName(selectedDate+".xlsx")
...
)
You should define an export to excel event handler (excelExport
) as:
excelExport: function(e) {
var selectedDate = ...
e.workbook.fileName = selectedDate + ".xslx";
}
And it might look like:
<script type="text/javascript">
var selectedDate ="";
$("#startDate").change(function (e) {
selectedDate = $(this).val();
var sd = selectedDate.split('/');
selectedDate = sd[0] + "-" + sd[1] + "-" + sd[2];
});
var grid = $("#grid").data("kendoGrid");
grid.bind("excelExport", function(e) {
e.workbook.fileName = selectedDate + ".xslx";
});
</script>
Upvotes: 2