BoldSignEasily embed eSignatures in your .NET applications. Free sandbox with native SDK available.
<button type="button" onclick="Data()">BindDataSource</button>
@(Html.EJ().Grid<object>("Grid")
.AllowPaging()
.Columns(col =>{
col.Field("OrderID").HeaderText("EvidID").IsPrimaryKey(true).Width(55).Add();
col.Field("CustomerID").HeaderText("Broj").Width(55).Add();
. . .
})
)
<script type="text/javascript">
function Data() {
$.ajax({
type: "GET",
url: "/Grid/Data",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data) {
var gridObj = $("#Grid").ejGrid("instance");
gridObj.dataSource(data);//dataSource method
}
});
}
</script>
Serverside:-
public object Data()
{
BindDataSource();
IEnumerable Data = order.Take(10).ToList();
return Json(Data, JsonRequestBehavior.AllowGet);
}
[ValidateInput(false)]
public void ExportToExcel(string GridModel)
{
BindDataSource();
ExcelExport exp = new ExcelExport();
var DataSource = order.ToList().Take(10);
GridProperties obj = ConvertGridObject(GridModel);
exp.Export(obj,DataSource, "Export.xlsx", ExcelVersion.Excel2010, false, false, "bootstrap-theme");
}
. . .
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)
{
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;
}
|
@(Html.EJ().Grid<object>("Grid")
.Datasource((IEnumerable<object>)ViewBag.datasource)
.Columns(col =>{
col.Field("OrderID").HeaderText("EvidID").IsPrimaryKey(true).Width(55).Add();
})
)
<script type="text/javascript">
function load(args) {
this.ignoreOnExport.splice(this.ignoreOnExport.indexOf('dataSource'), 1);
}
</script>
Serverside:-
[ValidateInput(false)]
public void ExportToExcel(string GridModel)
{
BindDataSource();
ExcelExport exp = new ExcelExport();
var DataSource = order.ToList().Take(10);
GridProperties obj = ConvertGridObject(GridModel);
exp.Export(obj,(IEnumerable)obj.DataSource, "Export.xlsx", ExcelVersion.Excel2010, false, false, "bootstrap-theme");
}
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<Orders>>(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;
}
|