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
8920
whg : calculate total on the client side
posted

2538.test01.zip

Attached project with hierarchical grid and dataset as data source.. please show how to add calculation of the total  of the amounts on the child records on the parent record on the client side when value of the child records are changing.. Please show it on the attached project.

Thanks.

Parents
  • 6365
    Verified Answer
    Offline posted

    Hello Michael,

    Thank you for the sample application you have provided.

    In order to update a parent row's cell based on the values of all its child rows, I can suggest you handle the CellExitedEditMode client-side event of the CellEditing behavior of the child band.
    This will allow you to recalculate and apply the new value of the parent row's cell whenever one of the corresponding cells of its child rows has been updated.

    For example:

    <ig:EditingCore AutoCRUD="False" BatchUpdating="True">
    <Behaviors>
    <ig:CellEditing>
    ...
    <%--=================== CellEditingClientEvents ===================--%>
    <CellEditingClientEvents ExitedEditMode="childCellExitedEditMode" />
    </ig:CellEditing>
    </Behaviors>
    </ig:EditingCore>

    function childCellExitedEditMode(sender, args) {
    // Terminate execution if the edited cell is not from the 'amount' column
    if (args.getCell().get_column().get_key() !== "amount")
    return;
    
    let parentRow = args.getCell().get_row().get_grid().get_parentRow();
    let childRows = parentRow.get_rowIslands()[0].get_rows();
    let childRowsCount = childRows.get_length();
    
    let newTotalValue = 0;
    for (let i = 0; i < childRowsCount; i++) {
    let childRow = childRows.get_row(i);
    newTotalValue += childRow.get_cellByColumnKey('amount').get_value();
    }
    
    parentRow.get_cellByColumnKey('total').set_value(newTotalValue);
    }

    I have attached a sample application that demonstrates the approach from above.

    If you have any questions, please let me know.

    2438.test01(Modified).zip

Reply Children
No Data