Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
2165
Get row index
posted

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);
}
});

Parents
No Data
Reply
  • 8421
    Verified Answer
    posted

    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);
        }
       });

Children