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
670
Updating Child Rows from Updated Parent Row
posted

I would like to set the values of a child row column based on the value of a parent row cell when the user changes the value of the parent row cell. Furthermore if the parent row is not expanded, I wish to expand the row, then update the cells in the child rows.

 So far the order of events is not in my favor, apparently the child rows are expanded before the update cell event has fired.

I am using XML mode with AJAX on.

  • 670
    Verified Answer
    posted

    I have developed a solution to this problem using client script (preferable because I want to avoid postbacks until the user saves the changes).

     I respond to the aftercellupdated event and check the status of the current row.

    If the row has never been expanded (getExpanded() is null or undefined) then expand the row and work with the child rows in the AfterRowExpanded event.

    If the row has been expanded but is contracted, expand the row. The AfterRowExpanded event handles the child rows.

    If the row is expanded then process the child rows.

    function UltraWebGrid_AfterCellUpdateHandler(gridName, cellId){

    // Obtain the row of the updated cell

    oRow = igtbl_getRowById(cellId);

    // check to see if the row can be expanded

    if (oRow.Expandable==true) {

    // check to see if the row has been expanded yet

    if (!(oRow.getExpanded()==null)) {

    // ensure row is expanded

    if (oRow.getExpanded()==false) {

    // no row expanded event fires since this row was // previously expanded

    oRow.setExpanded(true);

    }

    else {

    // Obtain the value of the updated cell

    oCell = oRow.getCellFromKey("Included");

    var includedVal = oCell.getValue();

     

    // Obtain the collection of child rows

    var oChildRows = oRow.Rows;

     

    // step through the child rows and set corresponding // column to updated cell value.

    for (var r = 0; r<oRow.ChildRowsCount; r++) {

    var oChildRow = oChildRows.getRow(r);

    var oChildCell = oChildRow.getCellFromKey("Included");

    oChildCell.setValue(includedVal,false);

    }

    }

    }

    else {

    // Expand the row (causes a row expanded event to fire)

    oRow.setExpanded(true);

    }

    }

    }

    function UltraWebGrid_AfterRowExpandedHandler(gridName, rowId){

    // Obtain the row of the updated cell

    oRow =igtbl_getRowById(rowId);

    // Obtain the value of the updated cell

    var oCell = oRow.getCellFromKey("Included");

    var includedVal = oCell.getValue();

    // Verify if the row has child rows (precaution)

    if (oRow.ChildRowsCount>>0) {

    // Obtain the collection of child rows

    var oChildRows = oRow.Rows;

    // step through the child rows and set corresponding // column to updated cell value.

    for (var r = 0; r<oRow.ChildRowsCount; r++) {

    var oChildRow = oChildRows.getRow(r);

    var oChildCell = oChildRow.getCellFromKey("Included");

    oChildCell.setValue(includedVal,false);

    }

    }

    }