What is the right way to set a two level igHierarchicalGrid for batch updating and get its aggregated transactions in the client?
In the attached example (inspired on some code found in this forum) the grid let the user to add, modify and delete rows from level 1 (categories) and level 2 (products). For simplicity in this example I am not catching deleted rows. The problem is that I can't get transactions from level 2. Also, in order to add rows at level 2 AutoCommit must be set to true (when parent row is new) , this is an issue because a) I cant use aggregated transactions (according to documentation: This option takes effect only when autoCommit is set to false), that means bigger packets sent to the server, b) italics applied to edited rows are lost so user can't see what has been edited. Is there a way to fix this?
Thank you so much Stamen! I'll be waiting anxiously for your answer. ;)
Hello Luis,
To answer your questions:
- Yes, transactionsAsString basically calls JSON.stringify before returning the transaction log.
- I think the reason is that the event handler posted by Petar is meant to work on a flat grid. In the hierachical scenario to commit the changes coming from the grid that has thrown the "rowAdded" event you need to do something like this:
$(document).delegate("#grid1", "iggridupdatingrowadded", function (evt, ui) { ui.owner.grid.commit();});
The difference from Petar's sample code is that he is using a selector that returns the parent table and calls commit on it. My sample uses the event args to get a reference to the grid that has a row added and call commit on it directly. Due to the event bubbling the "rowAdded" of each child grid will get captured by a handler attached to the parent one.
- As for the third question, I managed to reproduce what you reported and I am currently doing some further research on what's causing the foreignKeys to not get populated for child rows created for a new parent row. I should be able to provide you with a workaround for the issue a bit later today.
Best regards,
Stamen Stoychev
Well, I found the best solution till now: make your own aggregated transaction log :) When I finish it I would like to share it here.
Please Petar, do not leave me alone! Be a good guy and help me :)
Please guys I need to get this fixed before next monday :( Question 3 is the most important to me. I have tried many things. This is what I have till now:
$(document).delegate("#MyGrid", "iggridupdatinggenerateprimarykeyvalue", function (evt, ui) { pk = pk - 1; ui.value = pk; });
$(document).delegate("#MyGrid", "iggridupdatingrowadded", function (evt, ui) {
// getting the parent grid row data var parentRow = $(ui.owner.element).parents("tr[data-container='true']").prev("tr"); var parentRowId = $(parentRow).attr("data-id"); if (parentRowId == undefined) return;
var parentRowGrid = $(parentRow).closest("table"); var parentKey = $(parentRowGrid).igGrid("getCellValue", parseInt(parentRowId), "Id");
// doesn't work //ui.values["CategoryId"] = parentKey;
// doesn't work //var dataRecord = $("#MyGrid").igGrid("findRecordByKey", ui.rowID); //dataRecord.CategoryId = parentKey;
// doesn't work //var childGrids = $("#MyGrid").igHierarchicalGrid("allChildren"); //var dataRecord = $(childGrids).igGrid("findRecordByKey", ui.rowID); //dataRecord.CategoryId = parentKey;
/* with this (last two line of code) I receive the CategoryId but when parsing it in the server there is an error:'System.Runtime.Serialization.SerializationException' I think it is because transactions are not aggregated (because of AutoCommit(true), and because AgreggateTransactions(true) and because if I don't use AutoCommit(true) then new children on new parents can't be added... it is a chain of issues :(
This is what the server receive:
transactionsLevel1:[{"type":"newrow","tid":"c055","row":{"Id":-1,"Name":"AAA","Description":"AAA"},"rowId":-1}]transactionsLevel2:[{"type":"newrow","tid":"99b5","row":{"Id":-2,"Name":"BBBBB","CategoryId":null},"rowId":-2},{"type":"cell","rowId":-1,"tid":"a635","col":"CategoryId","value":-1}]
As you see there are two transactions for the rowId:-2, one when row is added and another when CategoryId is updated. */
var childGrids = $("#MyGrid").igHierarchicalGrid("allChildren"); $(childGrids[0]).igGridUpdating("setCellValue", ui.rowID, "CategoryId", parentKey);
});