Hello,
I'm testing the MVC Hierarchical grid with the following code. I can't edit the child rows and I can't select one child row, it selects all the child row.
@(Html.Infragistics() .Grid(Model) .ID("igGrid") .AutoGenerateColumns(false) .PrimaryKey("ID") .Features(f => { f.Updating().EditMode(GridEditMode.Row); }) .UpdateUrl(Url.Action("CfgCatalogsSaveData")) .Columns(column => { column.For(x => x.ID).HeaderText("ID"); column.For(x => x.Name).HeaderText("Name"); }) .ColumnLayouts(layouts => { layouts.For(x => x.CfgCatalogItems) .PrimaryKey("ID") .AutoGenerateColumns(false) .AutoCommit(true) .Columns(childcols1 => { childcols1.For(x => x.ChoiceValue).HeaderText("Valeur"); childcols1.For(x => x.Label).HeaderText("Texte"); childcols1.For(x => x.Congruent).HeaderText("Compliant"); }) .Features(g => { g.Updating().EditMode(GridEditMode.Row); }) ; })
.DataBind() .Render())
Best regards,
Alain
Hello Stamen,
Yes, I used the igGrid and not the igHierachicalGrid.
Now I receive the children data but I have still 2 problems:
1)If I add a new children, in the MVC controller I receive the children data but I haven't the parent ID ?
2) When I modify or add a parent, after the record is in italic to show the modification. But when I change/add a children, the record is not in italic.
@using Infragistics.Web.Mvc;@model IQueryable<NCH.Quality.QModels.CfgCatalog>
<h2>Catalogues</h2>
@(Html.Infragistics() .Grid(Model) .ID("igGrid") .AutoGenerateColumns(false) .PrimaryKey("ID") .Features(f => { f.Updating().EditMode(GridEditMode.Row); }) .UpdateUrl(Url.Action("CfgCatalogsSaveData")) .Columns(column => { column.For(x => x.ID).HeaderText("ID"); column.For(x => x.Name).HeaderText("Nom Catalogue"); }) .ColumnLayouts(layouts => {
layouts.For(x => x.CfgCatalogItems) .PrimaryKey("ID") .ForeignKey("CfgCatalogID") .AutoGenerateColumns(false) .AutoCommit(true) .Columns(childcols1 => { childcols1.For(x => x.ID).HeaderText("ID"); childcols1.For(x => x.ChoiceValue).HeaderText("Valeur"); childcols1.For(x => x.Label).HeaderText("Texte"); childcols1.For(x => x.Congruent).HeaderText("Compliant"); childcols1.For(x => x.CfgCatalogID).HeaderText("CatID").Hidden(true); }) .Features(g => { g.Responsive(); g.Updating().ColumnSettings(cs => { cs.ColumnSetting().ColumnKey("ID").ReadOnly(true); cs.ColumnSetting().ColumnKey("ChoiceValue").EditorType(ColumnEditorType.Numeric).Required(true); cs.ColumnSetting().ColumnKey("Label").EditorType(ColumnEditorType.Text).Required(true); cs.ColumnSetting().ColumnKey("Congruent").EditorType(ColumnEditorType.Checkbox).Required(true); cs.ColumnSetting().ColumnKey("CfgCatalogID").ReadOnly(true); }).EditMode(GridEditMode.Row).Validation(true); g.Sorting() ; }).UpdateUrl(Url.Action("CfgCatalogsSaveData")) ; })
<input type="button" id="saveChanges" class="button-style" value="Enregistrer" /><input type="button" id="undo" class="button-style" value="Undo" />
<script type="text/javascript">
function GridModalLoadingIndicator(grid) { var modalBackground = $("<div class='ui-widget-overlay ui-iggrid-blockarea' style='position: absolute; display: none; width: 100%; height: 100%;'></div>").appendTo(grid.data("igGrid").container()); function _show() { modalBackground.show(); grid.data("igGrid")._loadingIndicator.show(); } function _hide() { modalBackground.hide(); grid.data("igGrid")._loadingIndicator.hide(); } return { show: _show, hide: _hide } }
$(function () { var loadingIndicator;
var grid = $("#igGrid");
loadingIndicator = new GridModalLoadingIndicator(grid); $("#saveChanges").igButton({ labelText: $("#saveChanges").val(), disabled: true }); $("#undo").igButton({ labelText: $("#undo").val(), disabled: true });
$("#saveChanges").on('igbuttonclick', function (e) { //grid.igGrid("saveChanges", function saveSuccess() { // loadingIndicator.hide(); //});
grid.igHierarchicalGrid("saveChanges", function saveSuccess() { loadingIndicator.hide(); }); loadingIndicator.show(); $("#undo").igButton("disable"); $(this).igButton("disable"); return false; } );
$("#undo").on('igbuttonclick', function (e, args) { updates = $.extend({}, grid.data('igGrid').pendingTransactions()); $.each(updates, function (index, transaction) { grid.igGrid("rollback", transaction.rowId, true); });
$("#undo").igButton("disable"); $("#saveChanges").igButton("disable");
return false; } );
grid.on("iggriddatabinding", function (e, args) { loadingIndicator.show(); });
grid.on("iggriddatabound", function (e, args) { loadingIndicator.hide(); });
grid.on("iggridupdatingrowdeleted", function (e, args) { $("#undo").igButton("option", "disabled", false); $("#saveChanges").igButton("option", "disabled", false); });
grid.on("iggridupdatingrowadded", function (e, args) { $("#undo").igButton("option", "disabled", false); $("#saveChanges").igButton("option", "disabled", false); }); grid.on("iggridupdatingeditrowended", function (e, args) { if (args.update) { $("#undo").igButton("option", "disabled", false); $("#saveChanges").igButton("option", "disabled", false); } });
});
</script>
----------------------------------------------------------------------
public class CfgCatalogsController : Controller { private NCH.Quality.QDAL.QContext db = new NCH.Quality.QDAL.QContext();
public ActionResult Index() { var model = db.CfgCatalogs; return View(model); } public ActionResult CfgCatalogsSaveData() { GridModel gridModel = new GridModel(); List<Transaction<NCH.Quality.QModels.CfgCatalog>> transactions = gridModel.LoadTransactions<NCH.Quality.QModels.CfgCatalog>(HttpContext.Request.Form["ig_transactions"]); List<Transaction<NCH.Quality.QModels.CfgCatalogItem>> transactions2 = gridModel.LoadTransactions<NCH.Quality.QModels.CfgCatalogItem>(HttpContext.Request.Form["ig_transactions"]); var model = db.CfgCatalogs;
foreach (Transaction<CfgCatalog> t in transactions) { if (t.type == "newrow") { model.Add(t.row); } else if (t.type == "deleterow") { model.Remove(model.Find(Convert.ToInt32(t.rowId))); } else if (t.type == "row") { CfgCatalog o = model.Find(Convert.ToInt32(t.rowId)); o.Name = t.row.Name; o.Name = t.row.Name; } }
db.SaveChanges();
JsonResult result = new JsonResult(); Dictionary<string, bool> response = new Dictionary<string, bool>(); response.Add("Success", true); result.Data = response; return result; } }
Hello Alain,
Could you paste the code with the saveChanges call? You may be targeting the igGrid parent widget instead of the igHierarchicalGrid widget. The latter bundles all transactions for all layouts and should work for your case. You can find a code snippet with sample usage here.
Stamen Stoychev
It works, thank you.
But I have another problem. I save the data to the server with UpdateUrl(...), but the data added or changed in the children are never send to the server. It works properly for the parent.
public ActionResult CfgCatalogsSaveData() { GridModel gridModel = new GridModel(); List<Transaction> transactions = gridModel.LoadTransactions(HttpContext.Request.Form["ig_transactions"]);//List<Transaction> transactions2 = gridModel.LoadTransactions(HttpContext.Request.Form["ig_transactions"]);
foreach (Transaction t in transactions) { if (t.type == "newrow") { //model.Add(t.row); } else if (t.type == "deleterow") { //model.Remove(model.Find(Convert.ToInt32(t.rowId))); } else if (t.type == "row") { //CfgUnit o = model.Find(Convert.ToInt32(t.rowId)); //o.Name = t.row.Name; //o.Note = t.row.Note; } }
JsonResult result = new JsonResult(); Dictionary response = new Dictionary(); response.Add("Success", true); result.Data = response; return result; }
I haven't found an example, could you help me ?
Both issues are most likely related to the fact you are not defining the ID column for the child layout but still set it as a primary key. Updating requires that there is a correct and unique primary key defined available for the data source you are editing. Selection would select all rows that have the same PK and since the PK column is not defined all values for it will be 'null' causing the behavior you are experiencing.
I hope this helps! Please, let me know if you have any other questions or concerns!