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..
after seeing your responses i did some testing...
so the problem appears if i do batch updates, but if i save the information every time i do a add, delete or update and then call save changes it is now possible...
it detects if the row is a child row or a father row, depending on the value of the layout...
but if i do some batch updates change a child row and then change a father row, it only return the change on the father grid...
one other thing that i though i should try is grid load on demand...but i will create a new project see what comes up..
is it possible instead of using the model in a direct way, create a view model with the info that i want?
Hello Sergio,
Thank you for your reply.
A sample presenting batch updating for both parent and child grid rows could be found in the following resource:
http://igniteui.com/hierarchical-grid/editing-dataset
To your question regarding the LoadOnDemand feature it could be enabled by the following code:
.Features(features =>
{
…
features.LoadOnDemand();
})
More information on this feature could be found in the following resource:
http://help.infragistics.com/Help/Doc/jQuery/2013.2/CLR4.0/html/igHierarchicalGrid_Load_on_Demand.html
Using domain model or view model does not affect the grid behavior. It is a design decision and since the data passed by the controller corresponds to the model associated to the view the project is expected to work correctly. You might be interested in reading through the thread below:
http://stackoverflow.com/questions/11064316/what-is-viewmodel-in-mvc
Hope this helps. If you have any further questions feel free to contact us again.
now i am completly lost...
i have created a project using mvc and EF4.0
i was following this example http://es.infragistics.com/community/blogs/damyan_petev/archive/2012/02/15/jquery-hierarchical-grid-load-on-demand.aspx
and i according to this we can achive load on demand from mvc helper or by jquery, but to use it with jquery i need to use oData Protocol?am i wrigth?
now when i created this topic i was using a hierarchical grid that load all data on initialization, then i add the enable add row for both parents and child rows..
when savechanges method was called if the changes was only a child row, or a father row, it was detecting the data, and we could see that the value of the layout field was diferent ...father was null, and the child was Produtcs, but when i tried to do batch updates (ie add father row, then add a child row) it was only detecting the information about the father..
i now created a new project using hierarchicalgrid and load on demand capability, and if i do some batch updates it detects both changes...
so basically, if i use load on demand with hierarchiclagrid i can do batch updates, if i use load all it is not possible to do batchupdates,althoug it detects the changes if i do one thing at a time (add father row then call save changes, or add child row then call save changes)?
am i right?
thanks
Load on demand could be used both with oData Protocol and without it. The feature is available both in the MVC wrapper and by using pure jQuery without the wrapper. Data retrieving is internally implemented so, as I mentioned in my previous post, all you should do to enable load on demand is adding its declaration in the features section:
To your comment regarding the save changes implementation - have you tested this sample?
If anything new comes up feel free to also add it to the thread.
Hi, thanks for responding to my question.
using the example descibed i made the changes according to the link refered above..
sorry if my question above was not very well described..
with both examples the diference that i detect is related to batch updates,,,
what i want to know if the problem is real (maybe i did some mistake.), i mean, if i load all data i can not do batch updates, if i use load on demand i can do batch updates?
i am asking this because the same model ,one with load on demand and another with load all, why can i do bacth updates if using load on demand capability, or if using load all i cant do it...
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?