Question #1: Is $(ui.element).data("row-idx") always equals to ui.owner._rowIndex?
Question #2: Is ui.owner._rowIndex the right index to get the corresponding row from the view?
I want to be sure I will always get the right Description and Name from the view:
$(document).delegate("#MyGrid", "iggridupdatingeditrowended", function (evt, ui) {
if ($(ui.owner.element).data("level") === 0) { // It's a Parent
var pRow = $('#MyGrid').data("igGrid").dataSource.dataView()[ui.owner._rowIndex];
// Show category's decription console.log(pRow.Description);
} else { // It's a Child
var pRow = $(ui.owner.element).parents("tr[data-container='true']").prev("tr");
// Get parent's index var pViewIdx = $(pRow).data("row-idx");
// Get children var cRows = $('#MyGrid').data("igGrid").dataSource.dataView()[pViewIdx].Products.Records;
// Show the name of the edited product console.log(cRows[ui.owner._rowIndex].Name); }});
Hello Luis,
The editRowEnded event exposes a property called rowID off of the ui event argument. It is recommended that you use this for accessing rows rather than the index and then pass that value to the grid's findRecordByKey method to get access to the record you want. In the case of hierarchical grid you're going to want to find the container grid widget for the record and then call findRecordByKey off of the widget. Fortunately, the ui also exposes the container grid in the form of ui.owner.grid. Using this, you can simplify the logic that you have to the following:
$('#MyGrid').on('iggridupdatingeditrowended', function (evt, ui) { var row = ui.owner.grid.findRecordByKey(ui.rowID); if (row.Description) { // Show category's description console.log(row.Description); } else if (row.Name) { // Show the name of the edited product console.log(row.ShipName); } });
Hello Jason, I have a new issue, this time related to iggridupdatingrowadded, in this case findRecordByKey returns null for a new child when the parent is new too. I have solved that using ui.values for every cell, it works even with hidden columns. May I trust this solution? Is there a better way?
$(document).delegate("#MyGrid", "iggridupdatingrowadded", function (evt, ui) {if (ui.owner.element.data("level") === 0) { // Parent console.log(ui.values["ParentId"]); } else { // Child. console.log(ui.values["ChildId"]); } });
It's perfect! thank you Jason, it works even with hidden columns. Thank you so much.