[GridController.cs] public ActionResult GridFeatures() { var DataSource = GetDataTale(); ViewBag.datasource = ConvertDataTableToJSON(DataSource); return View(); } private static object ConvertDataTableToJSON(DataTable dt) { JavaScriptSerializer jSonString = new JavaScriptSerializer(); List<Dictionary<string, object>> rows = new List<Dictionary<string, object>>(); Dictionary<string, object> row; foreach (DataRow dr in dt.Rows) { row = new Dictionary<string, object>(); foreach (DataColumn col in dt.Columns) { row.Add(col.ColumnName, dr[col]); } rows.Add(row); } string serialize = jSonString.Serialize(rows); var data = jSonString.Deserialize<IEnumerable<object>>(serialize); return data; } |
(Html.EJ().Grid<object> ("FlatGrid") .Datasource((System.Data.DataTable)ViewBag.dataSource) ) |
[HomeController.cs] { var DataSource = GetDataTale(); ViewBag.datasource = datalist; return View(); } private DataTable GetDataTale() { DataTable dt = new DataTable("Table"); dt.Columns.AddRange(new DataColumn[4] { new DataColumn("pictureURL", typeof(string)), … DataRow dr = null; for (int i = 0; i <= 10000; i++) { dr = dt.NewRow(); dr[0] = "<img src ='../ejThemes/Employee/6.png'>"; … } return dt; [Index.cshtml] @(Html.EJ().Grid<object>("DetailGrid") .Datasource((IEnumerable<object>)ViewBag.datasource) .AllowPaging(true) .Columns(col => { col.Field("pictureURL").HeaderText("Employee Image").TextAlign(TextAlign.Center).Width(110).Add(); … }) ) |
[Index.cshtml] @(Html.EJ().Grid<object>("DetailGrid") .Datasource(ds => ds.Json((IEnumerable<object>)ViewBag.datasource).UpdateURL("/Home/Update") .InsertURL("/Home/Insert").RemoveURL("/Home/Remove").Adaptor(AdaptorType.RemoteSaveAdaptor)) .AllowPaging(true) .Columns(col => { col.Field("pictureURL").HeaderText("Employee Image").TextAlign(TextAlign.Center).Width(110).Add(); col.Field("Id").HeaderText("ID1").TextAlign(TextAlign.Right).Width(125).Add(); col.Field("Name").HeaderText("Value").Width(100).Add(); col.Field("Qty").HeaderText("Qty").Width(100).TextAlign(TextAlign.Right).Priority(2).Add(); }) ) [Controller.cs] public ActionResult Update(EditableOrder value) { // perform update opertion } public ActionResult Insert(EditableOrder value) { //perform add operation } public ActionResult Remove(int key) { //perform delete operation } |