Hi, i was tryind to do a add row to a hierarchical grid, using the api available.
The problem is that when when i add a root row , and then call savechanges it detects the root row and add it to the database, if i try to add a child row it ig_transactions come empty according to firebug.
if i add a new father row, then add a child row to another father, the ig_transactions comes with a miscellanious info about..
i am using your example of ighierarchicalgrid
i add the add row features to root row and child row..
so in this first image we can see the grid and the grid is load with some info.
i then press add new row, and add a root row with some data, then i press the save button that call me the a action defined in UpdateUrl(Url.Action("save"))
the method save is called and the ig_transaction has this value
ig_transactions[{"type":"newrow","tid":"4eb2","row":{"ig_pk":5,"ID":1,"Name":"sasa","IsActive":false},"rowId":5}]
[{"type":"newrow","tid":"4eb2","row":{"ig_pk":5,"ID":1,"Name":"sasa","IsActive":false},"rowId":5}]
lets try that with 2 root rows
[{"type":"newrow","tid":"4eb2","row":{"ig_pk":5,"ID":1,"Name":"sasa","IsActive":false},"rowId":5},{"type":"newrow","tid":"a14f","row":{"ig_pk":5,"ID":2,"Name":"sasas","IsActive":false},"rowId":5}]
[{"type":"newrow","tid":"4eb2","row":{"ig_pk":5,"ID":1,"Name":"sasa","IsActive":false},"rowId":5},{"type"
:"newrow","tid":"a14f","row":{"ig_pk":5,"ID":2,"Name":"sasas","IsActive":false},"rowId":5}]
from this lines of ig_transaction we can see that we are creating new rows with some info inside..
but we can also see that ig_pk is 5(infragistis grid primary key is that???)what is the meaning of this vallue 5 and the meaning ig_pk?
but this is not the only problem/doubt that i have...
the second image i am trying to add a root row, and then i am trying to add a child row to the root row number 2..
if i press save te ig_transacation send this [{"type":"newrow","tid":"d880","row":{"ig_pk":5,"ID":6,"Name":"sasas","IsActive":false},"rowId":5}]
[{"type":"newrow","tid":"d880","row":{"ig_pk":5,"ID":6,"Name":"sasas","IsActive":false},"rowId":5}]
as you can see it only send the information regarding the root row that was added,,,
what is the problem...
in the ig_transactions it should send the info about the 2 rows, the parent and the child row..
the method save is something like this
[ActionName("save")] public ActionResult save() { GridModel m = new GridModel(); JsonResult result = new JsonResult(); Dictionary response = new Dictionary(); List ListCustomer = new List(); ViewData["GenerateCompactJSONResponse"] = false; List<Transaction> categoryTransactions = m.LoadTransactions(HttpContext.Request.Form["ig_transactions"]); foreach (Transaction t in categoryTransactions) { } List<Transaction> productTransactions = m.LoadTransactions(HttpContext.Request.Form["ig_transactions"]); foreach (Transaction t in productTransactions) { } result.Data = response; return result; }
i have uploaded a example project with clients and produtcs..
Hello Sergio,
Thank you for your feedback!
In order to pass multiple models to the view one possible approach is to create a wrapper model consisting of them. More detailed explanation and sample code snippets could be found here:
http://stackoverflow.com/questions/944334/asp-net-mvc-view-with-multiple-models
Your grid initialization in the view will look like the code below:
Html.Infragistics().Grid(WrapperModel.Model1)
Html.Infragistics().Grid(WrapperModel.Model2)
Hope this helps.
Thanks Dimka Vardina, i manage to get it working using the code that you indicated and the ignite ui component.
As i said before i was fidelling with hierarchical grids , and i detected that a grid that load all info on initialization didnt detect the child transaction, and a grid that uses load demand functionality detects the child transactions.
on those two project grids i add the updating feature and i enabled the add row.
after those project i started a new project that i am doing..and i decided that i want to create a custom dialog box with some custom css, to add a child row,
in this case i detected some diferences between adding a main row, or adding a child row...
the diference was that in order to add a child row, i need to find the subrid and then i can add it.
adding a main row
$("#hierarchicalGrid").igGridUpdating("addRow", { data });
adding a child row need i bit more of coding..
var childGrids = $("#hierarchicalGrid").igHierarchicalGrid("allChildren"); $.each(childGrids, function (ix, grid) { var iIDRowFather = $(grid).closest("tr").prev().attr("data-id"); if (iIDRowFather == IDOnWhereIWantToAddTheChildRow) { $(grid).igGridUpdating("addRow", { data }); $(grid).igGrid("commit");$("#hierarchicalGrid").igHierarchicalGrid("saveChanges");} });
Thanks once again Dimka Vardina for your response, and to always trying to help...
i just need one more thing, for now, and that is, how can i have two hierarchicalgrid in the same view...
let say on the view i have:
Html.Infragistics().Grid(Model1)
Html.Infragistics().Grid(Model2)
how can i do that, and how can i diferentiate both models...int he controller can i send more that one GridMoldel object?
In order to enable updating it is need to add something like the code below in the section where the grid features are enabled: gridModel.Features.Add(new GridUpdating() { EditMode = GridEditMode.Row}); Back to the EditSaveChanges() description - two separate lists of transactions are used for each of the levels: one for the changes applied to the parent rows and one for the rows from all child grids. public ActionResult EditingSaveChanges() { ViewData["GenerateCompactJSONResponse"] = false; GridModel m = new GridModel(); // transactions for changes in rows from the parent grid List<Transaction> categoryTransactions = m.LoadTransactions(HttpContext.Request.Form["ig_transactions"]); foreach (Transaction t in categoryTransactions) { if (t.layoutKey == null) { if (t.type == "deleterow") { DataRow dr = this.CategoriesProducts.Tables["Categories"].Rows.Find(Int32.Parse(t.rowId)); this.CategoriesProducts.Tables["Categories"].Rows.Remove(dr); } else if (t.type == "row") { Category categoryRow = (Category)t.row; DataRow dr = this.CategoriesProducts.Tables["Categories"].Rows.Find(Int32.Parse(t.rowId)); if (categoryRow.CategoryName != null) { dr["CategoryName"] = categoryRow.CategoryName; } if (categoryRow.Description != null) { dr["Description"] = categoryRow.Description; } } } } // transactions for changes in rows from child grids List<Transaction> productTransactions = m.LoadTransactions(HttpContext.Request.Form["ig_transactions"]); foreach (Transaction t in productTransactions) { if (t.layoutKey == "Products") { if (t.type == "deleterow") { DataRow dr = this.CategoriesProducts.Tables["Products"].Rows.Find(Int32.Parse(t.rowId)); this.CategoriesProducts.Tables["Products"].Rows.Remove(dr); } else if (t.type == "row") { Product productRow = (Product)t.row; DataRow dr = this.CategoriesProducts.Tables["Products"].Rows.Find(Int32.Parse(t.rowId)); if (productRow.ProductName != null) { dr["ProductName"] = productRow.ProductName; } if (productRow.CategoryID != null) { dr["CategoryID"] = productRow.CategoryID; } if (productRow.UnitPrice != null) { dr["UnitPrice"] = productRow.UnitPrice; } if (productRow.UnitsInStock != null) { dr["UnitsInStock"] = productRow.UnitsInStock; } dr["Discontinued"] = productRow.Discontinued; } } } JsonResult result = new JsonResult(); Dictionary response = new Dictionary(); response.Add("Success", true); result.Data = response; return result; } Please note that if it is needed to work with three, four, … n level hierarchical grid it is needed to add a separate transaction list for each level. Hope this helps. If you have any specific questions don’t hesitate to contact me again.
Apologies for the misleading information regarding the load on demand feature!
It is not needed to add custom functionality to enable it as I have mentioned. In order to set load on demand appropriately the hierarchical grid should be implemented in the code behind. This will affect the updating implementation too. The following sample presents one possible implementation of the hierarchical grid from the code behind:
http://igniteui.com/hierarchical-grid/load-on-demand
I have added a short description of the sample below:
Two grid models are used in this sample. They are generated in the GetGridModel() and the GridLoadOnDemand() methods. The grid displayed on the page corresponds to GridLoadOnDemand(). The other method is included in the sample in order to present one more possible implementation.
Though updating is not enabled in both of the grid models of the sample a method which is responsible for processing of the update transactions is also included in the code. It is the EditSaveChanges() method which I have pasted in the response below for your reference...
hi, in this past weekend i was playing with hierarchical grid, and i detect some problems(or not)..
so i have a success changes handler...and i want to detect changes on main grid, and changes on the subgrid...
the problem is that i need to know where i am, i mean, if i call success changes handler on the main grid i can do this:
$("#hierarchicalGrid").igHierarchicalGrid("saveChanges"); $("#hierarchicalGrid").igGridUpdating("option", "saveChangesSuccessHandler", function (data) { var ResultOfSaveChanges = data.Success; CheckResultOfSaveChangesGrid(ResultOfSaveChanges) });
but if i am on the subgrid... i need to do this:
$("#hierarchicalGrid").igHierarchicalGrid("saveChanges"); $(grid).igGridUpdating("option", "saveChangesSuccessHandler", function (data) { var ResultOfSaveChanges = data.Success; CheckResultOfSaveChangesGridResultOfSaveChanges) });
in this case i need ti add the method to the current subgrid...
is it normal?
is it possible to add this method to all of the subrgids...on initialization?