<ej:Grid ID="OrdersGrid" runat="server" AllowPaging="true">
<ClientSideEvents ToolBarClick="toolBarClick" />
. . .
</ej:Grid>
<script type="text/javascript">
function toolBarClick(args) {
var proxy = this;
if (args.itemName == "Excel Export") {
args.cancel = true;
proxy.element.ejWaitingPopup("show");
var model = $.extend(true, {}, this.model);
if (this.ignoreOnExport) {
for (var i = 0; i < this.ignoreOnExport.length; i++)
delete model[this.ignoreOnExport[i]];
}
$.ajax({
type: "POST",
url: "/WebService1.asmx/ExportToExcel",
data: { GridModel: JSON.stringify(model) },//pass the grid model
success: function (response) {
proxy.element.ejWaitingPopup("hide");
alert("Grid Exported");
},
error: function (Result) {
alert("Error");
}
});
}
}
</script>
[WebMethod]
[ActionName("ExportToExcel")]
[AcceptVerbs("POST")]
public string ExportToExcel()
{
string gridModel = HttpContext.Current.Request.Params["GridModel"];
GridProperties gridProperty = ConvertGridObject(gridModel);
ExcelExport exp = new ExcelExport();
IEnumerable result = OrderRepository.GetAllRecords().ToList();
exp.Export(gridProperty, (IEnumerable)result, "Export.xlsx", ExcelVersion.Excel2010, false, false, "flat-lime", true, Server.MapPath("/outPut"));
return "success";
} |