@(Html.EJ().Grid<object>("FlatGrid") .Datasource((IEnumerable<object>)ViewBag.datasource) .ClientSideEvents(eve=>eve.ActionComplete("complete")) ) <script type="text/javascript"> function complete(args) { if (args.requestType == "filtering") args.model.filteredRecords = $("#FlatGrid").ejGrid("getFilteredRecords"); // getting the filtered records and storing it in grid model } </script> [CS] private GridProperties ConvertGridObject(string gridProperty) { . . . . foreach (KeyValuePair<string, object> ds in div) { if (ds.Key == "filteredRecords") { string serialize = serializer.Serialize(ds.Value); List<OrdersView> value = serializer.Deserialize<List<OrdersView>>(serialize);//serializing the filteredRecords stored in the gridmodel gridProp.DataSource = value ;//assigning the serialized data to the gridmodel dataSource } . . . . . } return gridProp; } public void ExcelExport(string GridModel) { GridProperties gridPropert = ConvertGridObject(GridModel); ExcelExport exp = new ExcelExport(); exp.Export(gridPropert, (IEnumerable)gridPropert.DataSource, "Export.xlsx", ExcelVersion.Excel2010, false, false, "flat-azure-dark");//passing the filtered data in the export method } |
public void ExcelExport() { string gridModel = HttpContext.Current.Request.Params["GridModel"]; JavaScriptSerializer serializer = new JavaScriptSerializer(); GridProperties gridPropert = ConvertGridObject(gridModel); // Get the grid properties Type test = GetTableType(gridPropert); // Get the dynamic table type var inst = Array.CreateInstance(test, 1); // Create instance of Array to the dynamic table type var data = serializer.Deserialize(this.ExportData, inst.GetType()) as object[]; // serialize the export data as object array ExcelExport exp = new ExcelExport(); exp.Export(gridPropert, data, "Export.xlsx", ExcelVersion.Excel2010, false, false, "flat-azure-dark"); public static Type GetTableType(GridProperties gridProperty) |