A more efficient approach is to create an Excel file using the actual data, rather than relying on the dataSource.
1]
To implement this, add the following code snippet to your HTML page:
$('#export').click(function () {
var title = "EmployeeData";
var id = guid();
var filter = $("#grid").data("kendoGrid").dataSource._filter;
var data = {
filter: filter,
title: title,
guid: id
};
$.ajax({
url: '/Employee/Export',
type: "POST",
dataType: 'json',
data: JSON.stringify(data),
contentType: "application/json; charset=utf-8",
success: function (result) {
window.location = kendo.format("{0}?title={1}&guid={2}", '/Employee/GetGeneratedExcel', title, id);
}
});
});
2]
Create a new method called "Export" in the controller:
[HttpPost]
public JsonResult Export(KendoGridFilter filter, string guid)
{
// Implementation details for exporting to Excel
}
3]
Additionally, add the method "GetGeneratedExcel" to the controller:
[HttpGet]
public FileResult GetGeneratedExcel(string title, string guid)
{
// Retrieve and serve the generated Excel file
}
For further reference, check out the project repository on GitHub.
Explore a live example of this functionality at this link, where you can export Employees to Excel with potential modifications to meet specific requirements.