$("#Grid").ejGrid({
load: function (args) {
this.ignoreOnExport.splice(grid.ignoreOnExport.indexOf('dataSource'), 1);
}
})
|
$("#Grid").ejGrid({
// the datasource "window.gridData" is referred from jsondata.min.js
dataSource:window.gridData,
allowPaging: true,
allowFiltering:true,
dataBound:databound,
toolbarSettings: { showToolbar: true, toolbarItems: [ej.Grid.ToolBarItems.ExcelExport] },
columns: [
.
.
]
});
});
function databound(args){
var grid = $('#Grid').ejGrid('instance');
grid.ignoreOnExport.splice(grid.ignoreOnExport.indexOf('dataSource'), 1);
}
|
public void ExportToExcel(string GridModel)
{
ExcelExport exp = new ExcelExport();
GridProperties obj = ConvertGridObject(GridModel);
exp.Export(obj, (IEnumerable)(obj.DataSource), "Export.xlsx", ExcelVersion.Excel2010, false, false, "flat-saffron");
}
private GridProperties ConvertGridObject(string gridProperty)
{
JavaScriptSerializer serializer = new JavaScriptSerializer();
IEnumerable div = (IEnumerable)serializer.Deserialize(gridProperty, typeof(IEnumerable));
GridProperties gridProp = new GridProperties();
foreach (KeyValuePair<string, object> ds in div)
{
if (ds.Key == "dataSource")
{
string serialize = serializer.Serialize(ds.Value);
gridProp.DataSource = serializer.Deserialize<List<OrdersView>>(serialize);//here we need to deserialize the gridDatasource
}
else
{
var property = gridProp.GetType().GetProperty(ds.Key, BindingFlags.Instance | BindingFlags.Public | BindingFlags.IgnoreCase);
if (property != null)
{
Type type = property.PropertyType;
string serialize = serializer.Serialize(ds.Value);
object value = serializer.Deserialize(serialize, type);
property.SetValue(gridProp, value, null);
}
}
}
return gridProp;
}
|