Hi
Ignite UI 13.2 - MVC 5
I have a hierarchical grid populated with parent/child data. I am using teh AddRow feature to add new rows to the grid.
The grid is on a page with other fields on it and I am serialising all of the data so that I can update all fields and the grid in one transaction.
In order to serialise the grid data I call the allTransactions method but it is not returning the child band data. I get the parent band data just fine but can't figure out how to get hold of the changes in the child band (at this point all of the changes are new rows (since I can't save them in order to update them later).
Here is my jQuery code, which is sitting behind a button click on the web page:
var url = "@Url.Action(BRASHjms.Controllers.JobController.ACTION_SaveJob, new {})";var oMaterialTransactions = JSON.stringify($("#MaterialGrid").igGrid("allTransactions"));var form = $('form').serialize(); // Serialize form data.var data = { __RequestVerificationToken: $('[name=__RequestVerificationToken]').val(), ig_MaterialTransactions : oMaterialTransactions, formData: form }; // Format it for our model.// Post to the server.$.post(url, data, saveResponse);
oMaterialTransactions only ever includes the top level, parent, data.
I tried .igHierarchicalGrid("allTransactions") but that throws an error because allTransactions is not a function of igHierarchicalGrid.
How do I get hold of the changes to the child band?
Regards,
Graeme Hart
Hello Graeme,
Thank you for contacting us!
About your question, the Hierarchical gridis composed of multiple igGrids for each level of hierarchy. So if you want to get the transactions for a specific child grid you will need to get that child grid instance and get its transactions. You can get all child grid elements for the hierarchical grid using the allChildren method:
//get all childs (igGrid's)var childrens = $("#grid1").igHierarchicalGrid("allChildren");
This will return a list with all the child grids. Once you get a specific child you can get its transactions via the allTransactions of that child grid. For example:
var allTransactions = [];
for (var i = 0; i < childrens.length; i++) { var trans = $(childrens[0]).data("igGrid").transactionsAsString(); allTransactions.push(trans);}
My suggestion is to use hidden field which will pass the transactions to some begin form.
Code snippet from the controller:
I have created a sample for you in order to show you my approach
Thanks for the reply and example.
I am struggling to get this to work on my system, however.
I can see what you are doing and I get that bit but my equivalent of your allTransactions array only contains my equivalent of changed items - no product information at all so I can't relate the changes back to the parent.
I have Material & Stone where you have Product and Item. My grid has the AddRow feature enabled so I can go in and add a new stone row (ie a child) click the save button and all I get is information about the stone. I don't even get the parent'id, even though it is a column in the stone grid. I can't determine which Material the new Stone row belongs to.
I have modified your example to set EnableAddRow to true rather than false and I see the same result - the item information comes through but it has no product row id in it so I can't determine which product to add the item to.
Can you think of a way to relate the new item rows back to the product?
Graeme
Hey Graeme,
Thank you for your patience,
Truly there is no information about the parent row, when the transaction of the child is returned, you can get the rowId, but this rowId belongs to the child
Have a look at the returned json:
[{"type":"row","tid":"073e","row":{"Id":1,"ItemName":"Breaddddd","Price":1.44},"rowId":1},
{"type":"row","tid":"342f","row":{"Id":2,"ItemName":"Honeyyyyy","Price":4.55},"rowId":2}]
If you want to get the parent grid transactions also, you can add them to another hidden field for example and from there to access them into the controller. This will return you the parent grid transactions:
var transactions = $("#grid1").igGrid("allTransactions");
Thanks for your answer. Unfortunately it only applies to modified rows and won't work for new ones as it just leaves me with two sets of transactions that cannot be related to each other since the parent transactions do not include the children, which is where I started with this problem.
I am rather surprised that the grid can display a hierarchical data set but it can't return hierarchical data or at the very least two sets of data with enough fields in them to derive the relationship between the two sets.
Maybe I am missing something - id & rowid look like the same value - is one of them the parent row id?
Any other suggestions?
I have found the parent id via a round about route, which I suspect is not future proof.
My hierarchical grid has parent rows for Material and child rows for Stone.
The following code is executed when the save button is clicked:
var oAllStoneTransactions = []; var oMaterialChildren = $("#MaterialGrid").igHierarchicalGrid("allChildren"); for(var i= 0; i < oMaterialChildren.length;i++){ var oStoneChild = $(oMaterialChildren[i]).data("igGrid").transactionsAsString(); oStoneChild = oStoneChild.replace("Width", "ParentID\":\"" + $(oMaterialChildren[i]).data("igGrid").element[0].id + "\", \"Width"); oStoneChild.parentId = $(oMaterialChildren[i]).data("igGrid").element[0].id; oAllStoneTransactions.push(oStoneChild); }
The line in bold turns this:
into this:
"[{"type":"newrow","tid":"1ac1","row":{"JobStoneID":1,"StoneNumber":"11","Length":22,"ParentID":"MaterialGrid_4000008_JobStone_child", "Width":33},"rowId":1}]"
I can then parse the ParentID string to get the ID of the parent row (4000008 in this example)
This is relying on the igGrid not changing the way it names elements and in element 0 being the parent row element. I am lucky that you chose to include the ID of the parent row in the element name of the child row but I am worried that a small change on your part will break my code.
Surely the child rows returned by transactionsAsString should include the ID of the parent row? Perhaps you could put this into the next release?
Unfortunately time preassurs on this project mean that I will have to go ahead with this bodge in the hope that you can come up with a better alternative soon.
I would still be interested in any alternatives that you can come up with that are less vulnerable.
Hello Graeme, maybe you will be interested on this:
http://ko.infragistics.com/community/forums/p/93201/461687.aspx#461687
Greetings.
OK thanks a lot Graeme! ;)
Hi Luis
Zdravko told me this, though I haven't tested it out since I got my system working as described above:
Issue "169561: Transactions of type "newrow" on child layouts should always include the foreign key in the transaction log" has been addressed in service release versions 2013.1, 2013.2, 2014.1, 2014.2.
The following additional notes have been provided regarding this issue:
This service release is now available under your account at the Infragistics Website. To download the service release, log in to ‘Account’ and select ‘Keys & Downloads’. Select the appropriate tab for this product; then the license key. The available service releases (Hot Fixes) should now be listed on the page.
So, if you make sure you have the latest release of the listed versions you should be OK.
Hi Graeme! Did you solve this issue? I am very interested on this topic too. Thanks.
Hello,I am just checking do you have the chance to check the new available Service Release?