Hi Jayaprakash !
I tested next code:
@(Html.EJ().Grid<object>("Grid")
.Datasource(((IEnumerable<object>)ViewBag.dataSource))
.AllowPaging()
.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);
});
})
.EditSettings(edit => edit.AllowEditing().AllowAdding().AllowDeleting().EditMode(
EditMode.Dialog))
.Columns(col =>
{
col.Field("RecordID").HeaderText("Record ID")
.IsPrimaryKey(true).TextAlign(TextAlign.Right).Add();
col.Field("CustomerID").HeaderText("Customer ID")
.IsPrimaryKey(true).TextAlign(TextAlign.Right).Add();
col.Field("CustomerName").HeaderText("Customer Name").Add();
col.Field("OrderID").HeaderText("Order ID").
IsPrimaryKey(true).Add();
col.Field("OrderList").HeaderText("Order List").EditTemplate(a => { a.Create("create").Read("read").Write("write"); }).Add();
})
)
with
public class OrderData
{
public int RecordID { get; set; }
public int CustomerID { get; set; }
public string CustomerName { get; set; }
public int OrderID { get; set; }
public IEnumerable<string> OrderList { get; set; }
public OrderData(int RecordID, int CustomerID, string CustomerName, int OrderID, IEnumerable<string> OrderList)
{
this.RecordID = RecordID;
this.OrderID = OrderID;
this.CustomerID = CustomerID;
this.CustomerName = CustomerName;
this.OrderList = OrderList;
}
}
and the controller
public ActionResult Index2()
{
List<OrderData> order = new List<OrderData>();
List<string> list = new List<string>();
list.Add("Cream");
list.Add("Milk");
list.Add("Eggs");
list.Add("Butter");
list.Add("Curd");
list.Add("yogurt");
List<string> list1 = new List<string>();
list1.Add("Cream");
list1.Add("Eggs");
list1.Add("Curd");
List<string> list2 = new List<string>();
list2.Add("Cream");
list2.Add("Milk");
list2.Add("Butter");
list2.Add("yogurt");
int recordID = 0;
for (int i = 1; i < 9; i++)
{
order.Add(new OrderData(recordID++, 1, "Sam", 2, list));
order.Add(new OrderData(recordID++, 2, "Mercy", 4, list1));
order.Add(new OrderData(recordID++, 3, "Jim", 2, list));
order.Add(new OrderData(recordID++, 4, "Dev", 6, list2));
order.Add(new OrderData(recordID++, 5, "Jessi", 4, list1));
order.Add(new OrderData(recordID++, 6, "Cath", 6, list2));
}
ViewBag.dataSource = order;
var drop = list.ToList();
var dropData = new List<object>();
foreach (var li in drop)
{
dropData.Add(new { value = li, text = li });
}
ViewData["data"] = dropData;
return View();
}
First
initialization of the grid in addInitTemplate: function () {
showed in addInitTemplate.png.
Second
initialization in addDialogEditingTemplate: function () {
showed in addDialogEditingTemplate.png.
As we
see primary keys are duplicated.
I attached project files in
MySampleSyncMvcApp_5a6ca04a.7z24
Attachment:
MySampleSyncMvcApp_5a6ca04a.7z