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
1070
Client Side Band Row Iteration
posted

I've just figure out a way to iterate of the rows and cells of a band but it really seems messy. Can someone tell me if there is a better way to do this. In this there is an attempt that I made to do this in what I thought was a simpler way but it does not work. Any comments would be welcomed.

Why when I update a single cell does this event fire multiple times? This is not what I expected. I really expected this to get fired once for the row/cell that was updated.

function afterCellUpdate(gridClientId, cellId) {
    var grid = igtbl_getGridById(gridClientId);
    var band = igtbl_getBandById(cellId);
    var cell = igtbl_getCellById(cellId);
    var row = igtbl_getRowById(cellId);
    var gridRows = grid.Rows;
    var bandKey = band.Key;

    if (bandKey == 'Invoice') {
        var discount = row.getCellFromKey('Discount').getValue();
        var childRowCount = row.ChildRowsCount;
        for (var i = 0; i < childRowCount; i++) {
            var childRow = row.getChildRow(i);
            childRow.getCellFromKey('Discount').setValue(discount);
        }
    }
    else if (bandKey == 'InvoiceItem') {
        var rateCell = row.getCellFromKey('Rate');
        var rate = rateCell.getValue();
        var discountCell = row.getCellFromKey('Discount');
        var discount = discountCell.getValue();
        var totalCell = row.getCellFromKey('Total');
        var total = rate * (1 - discount / 100);
        totalCell.setValue(total);

        var invoiceTotal = 0;

        // I tried this but it only iterates over a single top level band.
        // This does not iterate over the child band rows, why not?
//        for (var i = 0; i < gridRows.length; i++) {
//            gridRow = gridRows.getRow(i);
//            var bandKey = gridRow.Band.Key;
//            if (bandKey == 'InvoiceItem') {
//                var invoiceTotal = row.getCellFromKey('Total').getValue();
//            }
//        }

        // Iterate over the current Invoice.InvoiceItem collection.
        var parentRow = row.ParentRow;
        var parentBandKey = parentRow.Band.Key;
        var childRowCount = parentRow.ChildRowsCount;
        for (var i = 0; i < childRowCount; i++) {
            var childRow = parentRow.getChildRow(i);
            invoiceTotal += childRow.getCellFromKey('Total').getValue();
        }
       
        // getFirstRow Returns the first row of the current rows parent collection.
        // getChildRows

        var invoiceTotalCell = parentRow.getCellFromKey('Total');
        invoiceTotalCell.setValue(invoiceTotal);
    }
}

If I'm doing the following, why does it only iterate over a single band? The InvoiceItem band is never found, this only goes over the Invoice band.

for (var i = 0; i < gridRows.length; i++) {
    gridRow = gridRows.getRow(i);
    var bandKey = gridRow.Band.Key;
    if (bandKey == 'InvoiceItem') {
        var invoiceTotal = row.getCellFromKey('Total').getValue();
    }
}

Parents Reply Children
No Data