<ej-grid id="FlatGrid" allow-paging="true" details-data-bound="detailGridData" details-template="#GridContents"> . . . . .. </ej-grid> <script id="GridContents" type="text/x-jsrender"> <div id="gridTab{{:ID}}"> <div id="detailGrid{{:ID}}"></div> </div> </script> <script type="text/javascript"> function detailGridData(e) { var filteredData = e.data["Alarms"]; var data = ej.DataManager(filteredData) e.detailsElement.find("#detailGrid" + e.data["ID"]).ejGrid({ dataSource: data, columns: [ { field: "Description" }, { field: "Date" } ] }); } </script> |
<ej-grid id="FlatGrid" allow-paging="true" details-data-bound="detailGridData" details-template="#GridContents"> <e-datamanager json="ViewBag.child1" insert-url="/Home/CellEditInsert" remove-url="/Home/CellEditDelete" adaptor="remoteSaveAdaptor" /> <e-toolbar-settings show-toolbar="true" toolbar-items=@(new List<string>() {"add","delete","update","cancel" })> </e-toolbar-settings> <e-edit-settings allow-adding="true" allow-editing="true" allow-deleting="true" edit-mode="InlineForm" /> <e-columns> <e-column field="ID" is-primary-key="true" width="75"> </e-column> . . . </e-columns> </ej-grid> <script id="GridContents" type="text/x-jsrender"> <div id="gridTab{{:ID}}"> <div id="detailGrid{{:ID}}"></div> </div> </script> <script type="text/javascript"> function detailGridData(e) { var filteredData = e.data["Alarms"]; var data = ej.DataManager({ json: filteredData, insertUrl: "/Home/CellEditInsertDetail", removeUrl: "/Home/CellEditDeleteDetail", adaptor: "remoteSaveAdaptor", headers: [{ "ID": e.data["ID"] }] }) e.detailsElement.find("#detailGrid" + e.data["ID"]).ejGrid({ dataSource: data, editSettings: { allowAdding: true, allowDeleting: true }, toolbarSettings: { showToolbar: true, toolbarItems: ["add", "delete", "update", "cancel"] }, columns: [ //you can hide the columns from user using visible property //update the primarykey in server end using the isIdentity { field: "DetailsID", isIdentity: true, isPrimaryKey: true, visible: false }, { field: "Description" }, { field: "Date", format: "{0:MM/dd/yyyy}", editType: "datepicker" } ] }); } </script> public ActionResult CellEditInsertDetail([FromBody]CRUDModel<AlarmModel> value) { Random ran = new Random(); value.Value.DetailsID = ran.Next(); int readonlyID = int.Parse(Request.Headers["ID"]); Orders ord = order.Where(or => or.ID == readonlyID).FirstOrDefault(); ord.Alarms.Add(value.Value); return Json(value.Value); } public ActionResult CellEditDeleteDetail([FromBody]CRUDModel<AlarmModel> value) { int readonlyID = int.Parse(Request.Headers["ID"]); Orders ord = order.Where(or => or.ID == readonlyID).FirstOrDefault(); ord.Alarms.Remove(ord.Alarms.Where(al => al.DetailsID == int.Parse(value.Key.ToString())).FirstOrDefault()); return Json(value); } |