|
[GridFeatures.cshtml]
@(Html.EJ().Grid<EditableOrder>("FlatGrid")
.Datasource((IEnumerable<EditableOrder>)ViewBag.dataSource)
.AllowPaging()
.EditSettings(edit => { edit.AllowAdding().AllowDeleting().AllowEditing(); })
.ToolbarSettings(toolbar =>
{
toolbar.ShowToolbar().ToolbarItems(items =>
{
items.AddTool(ToolBarItems.Add);
items.AddTool(ToolBarItems.Edit);
items.AddTool(ToolBarItems.Delete);
items.AddTool(ToolBarItems.Update);
items.AddTool(ToolBarItems.Cancel);
});
})
)
[Editableorder.cs]
public class EditableOrder
{
[Display(Name = "Order ID")]
[Required(ErrorMessage = "OrderID is must")]
public int OrderID
{
get;
set;
}
[Display(Name = "Emp ID")]
[Required(ErrorMessage = "EmployeeID is must")]
public int? EmployeeID
{
get;
set;
}
[Display(Name = "City")]
public string ShipCity
{
get;
set;
}
[Display(Name = "Country")]
public string ShipCountry
{
get;
set;
}
[Display(Name = "Freight")]
public decimal? Freight
{
get;
set;
}
public bool Verified
{
get;
set;
}
|
.ChildGrid(cg=>cg.Datasource(ds => ds.URL(@Url.Action("Clienti_Servizi","Admin")).Adaptor(AdaptorType.UrlAdaptor)).QueryString("IDUtente").Locale(CultureInfo.CurrentCulture.TextInfo.CultureName).AllowPaging().IsResponsive(true) .Columns(col=> { col.Field("IDServizio").IsPrimaryKey(true).Visible(false).Add(); col.Field("NomeServizio").Add(); }))
public async Task<JsonResult> Clienti_Servizi(DataManager dm) { log4net.Config.XmlConfigurator.Configure(); log.Info("Inizio esecuzione Clienti_Servizi(Guid idUtente)"); List<ServiziVM> data = new List<ServiziVM>(); int count = 0; try { IEnumerable<ServizioCliente> servizi; servizi = await _servizioClienteRepository.GetServiziCliente(Guid.Parse(dm.Where[0].value.ToString())); if (servizi.Any()) { foreach (ServizioCliente sc in servizi) { Servizio s = new Servizio(); s = await _servizioRepository.GetServizio(false, sc.IDServizio); ServiziVM svm = new ServiziVM() { Deleted = s.Deleted, DescrizioneServizio = s.DescrizioneServizio, IDServizio = s.IDServizio, NomeServizio = s.NomeServizio }; data.Add(svm); } } count = data.Count(); JsonResult test = new JsonResult(); test = Json(new { result = data, count }); log.Info("Fine esecuzione Clienti_Servizi(Guid idUtente)"); } catch (Exception ex) { log.Error(string.Format("Errore:{0}", ex.InnerException == null ? ex.Message : ex.InnerException.Message)); throw ex; } return Json(new { result = data, count }); }
public class ServiziVM { [Key] public Guid IDServizio { get; set; } [Display(Name = "NomeServizio", ResourceType = typeof(Resources.Servizi))] [Required(ErrorMessageResourceType = typeof(Resources.Common), ErrorMessageResourceName = "CampoObbligatorio")] public string NomeServizio { get; set; } [Display(Name = "DescrizioneServizio", ResourceType = typeof(Resources.Servizi))] [Required(ErrorMessageResourceType = typeof(Resources.Common), ErrorMessageResourceName = "CampoObbligatorio")] public string DescrizioneServizio { get; set; } [Display(Name = "Eliminato", ResourceType = typeof(Resources.Servizi))] public bool Deleted { get; set; } }
|
@(Html.EJ().Grid<EditableOrder>("FlatGrid")
.Datasource(Model)
.AllowPaging()
.EditSettings(edit => { edit.AllowAdding().AllowDeleting().AllowEditing(); })
.ToolbarSettings(toolbar =>
{
toolbar.ShowToolbar().ToolbarItems(items =>
{
items.AddTool(ToolBarItems.Add);
items.AddTool(ToolBarItems.Edit);
items.AddTool(ToolBarItems.Delete);
items.AddTool(ToolBarItems.Update);
items.AddTool(ToolBarItems.Cancel);
});
})
.Columns(col =>
{
col.Field("OrderID").HeaderText("Order ID").IsPrimaryKey(true).Add(); ;
col.Field("CustomerID").HeaderText("Customer ID").Add(); ;
col.Field("EmployeeID").HeaderText("Employee ID").Add();
col.Field("ShipCity").HeaderText("Ship City").Add();
})
.ChildGrid(child =>
{
child.Datasource(ds => ds.URL("/Grid/DataSource").UpdateURL("NormalUpdate").InsertURL("NormalInsert").RemoveURL("NormalDelete").Adaptor(AdaptorType.UrlAdaptor))
.QueryString("EmployeeID")
.AllowPaging()
.EditSettings(edit => { edit.AllowAdding().AllowDeleting().AllowEditing(); })
.ToolbarSettings(toolbar =>
{
toolbar.ShowToolbar().ToolbarItems(items =>
{
items.AddTool(ToolBarItems.Add);
items.AddTool(ToolBarItems.Edit);
items.AddTool(ToolBarItems.Delete);
items.AddTool(ToolBarItems.Update);
items.AddTool(ToolBarItems.Cancel);
});
})
.Columns(col =>
{
col.Field("OrderID").HeaderText("OrderID").IsPrimaryKey(true).TextAlign(TextAlign.Right).Width(75).Add();
col.Field("ShipCity").HeaderText("ShipCity").Width(100).Add();
col.Field("Freight").Width(120).Add();
col.Field("ShipName").Width(100).Add();
});
}))
[controller]
public List<Orders> BindDataSource()
{
int code = 10000;
for (int i = 1; i < 50; i++)
{
order.Add(new Orders(code + 1, "TOMSP", i + 0, 2.3 * i, "M�nster", "Toms Spezialit�ten", new DateTime(1991, 05, 15), "Germany", "44087", false));
order.Add(new Orders(code + 2, "HANAR", i + 2, 3.3 * i, "Rio de Janeiro", "Hanari Carnes", new DateTime(1990, 04, 04), "Brazil", "05454-876", true));
order.Add(new Orders(code + 3, "VICTE", i + 1, 4.3 * i, "Lyon", "Victuailles en stock", new DateTime(1957, 11, 30), "France", "69004", true));
order.Add(new Orders(code + 4, "VINET", i + 3, 5.3 * i, "Reims", "Vins et alcools Chevalier", new DateTime(1930, 10, 22), "France", "51100", true));
order.Add(new Orders(code + 5, "SUPRD", i + 4, 6.3 * i, "Charleroi", "Supr�mes d�lices", new DateTime(1953, 02, 18), "Belgium", "B-6000", false));
code += 5;
}
return order;
}
public ActionResult NormalUpdate([FromBody]CRUDModel<Orders> myObject)
{
var ord = myObject.Value;
Orders val = order.Where(or => or.OrderID == ord.OrderID).FirstOrDefault();
val.OrderID = ord.OrderID;
val.EmployeeID = ord.EmployeeID;
val.CustomerID = ord.CustomerID;
val.Freight = ord.Freight;
val.ShipCity = ord.ShipCity;
return Json(myObject.Value);
}
public ActionResult NormalInsert([FromBody]CRUDModel<Orders> value)
{
order.Insert(order.Count, value.Value);
return Json(order);
}
public ActionResult NormalDelete([FromBody]CRUDModel<Orders> value)
{
order.Remove(order.Where(or => or.OrderID == int.Parse(value.Key.ToString())).FirstOrDefault());
return Json(value);
}
[Serializable]
public class Orders
{
public Orders()
{
}
public Orders(long OrderId, string CustomerId, int EmployeeId, double Freight, string ShipCity, string ShipName,
DateTime OrderDate, string ShipCountry, string ShipPostalCode, bool Verified)
{
this.OrderID = OrderId;
this.CustomerID = CustomerId;
this.EmployeeID = EmployeeId;
this.Freight = Freight;
this.ShipCity = ShipCity;
this.ShipName = ShipName;
this.OrderDate = OrderDate;
this.ShipCountry = ShipCountry;
this.ShipPostalCode = ShipPostalCode;
this.Verified = Verified;
}
public long OrderID { get; set; }
public string CustomerID { get; set; }
public int EmployeeID { get; set; }
public double Freight { get; set; }
public string ShipCity { get; set; }
public string ShipName { get; set; }
public string ShipCountry { get; set; }
public string ShipPostalCode { get; set; }
public bool Verified { get; set; }
public DateTime OrderDate { get; set; }
}
public ActionResult DataSource(DataManager dm)
{
IEnumerable Data = BindDataSource();
int count = Data.AsQueryable().Count();
Syncfusion.JavaScript.DataSources.DataOperations operation = new Syncfusion.JavaScript.DataSources.DataOperations();
Data = operation.Execute(Data, dm);
return Json(new { result = Data, count = count }, JsonRequestBehavior.AllowGet);
}
|