rice-framework/krad-web/src/main/webapp/krad/scripts/krad.utility.js
/**
 * Calculates the group total and places it in the totalTd provided using a clone of the
 *
 * @param cellsToTotal cell data to evaluate for the total
 * @param totalTd the td of the group total row to place the total
 * @param groupTotalDiv the totalDiv to clone and place the total in to be added to the totalTd
 * @param rowIndex index of the the group total row
 * @param columnIndex data column index
 */
Calculates the group total and places it in the totalTd provided using a clone of the


Calculates the group total and places it in the totalTd provided using a clone of the
function calculateGroupTotal(cellsToTotal, totalTd, groupTotalDiv, rowIndex, columnIndex) {
    var total = 0;
    var values = new Array();
    var hasInvalidValues = false;
    var extraData = groupTotalDiv.data("params");
    var functionName = groupTotalDiv.data("function");
    for (var i = 0; i < cellsToTotal.length; i++) {
        var currentCell = cellsToTotal[i];
        var isCellObject = currentCell != null && typeof currentCell === 'object';
        var value;
        if (isCellObject) {
            value = currentCell.val;
            if (value == null) {
                value = "";
            }
        }
        var isAddLine = !isCellObject && currentCell
            && jQuery(currentCell).find(":input[name^='newCollectionLines']").length;
        if (!isAddLine) {
            value = coerceTableCellValue(currentCell, true);
        }
        else {
            continue;
        }
        value = convertComplexNumericValue(value);
        if (value == undefined || (value && !jQuery.isNumeric(value))) {
            hasInvalidValues = true;
            continue;
        }
        if (value != "") {
            value = parseFloat(value);
            values.push(value);
        }
    }
    if (!hasInvalidValues) {
        if (extraData != undefined) {
            total = executeFunctionByName(functionName, window, values, extraData);
        }
        else {
            total = executeFunctionByName(functionName, window, values);
        }
    }
    else {
        total = "N/A";
    }
    var groupTotalDisplay = totalTd.find("[data-role='groupTotal'][data-function='" + functionName + "']");
    if (groupTotalDisplay.length == 0) {
        groupTotalDisplay = groupTotalDiv.clone();
        groupTotalDisplay = groupTotalDisplay.attr("id", groupTotalDisplay.attr("id") + "_" + rowIndex + columnIndex);
        groupTotalDisplay.find("[id]").each(function () {
            jQuery(this).attr("id", jQuery(this).attr("id") + "_" + rowIndex + columnIndex);
        });
        totalTd.append(groupTotalDisplay);
        groupTotalDisplay.show();
    }
    var totalValueSpan = groupTotalDisplay.find("[data-role='totalValue']");
    if (totalValueSpan.length) {
        totalValueSpan.html(total);
    }
    else {
        var newSpan = jQuery("<span data-role='totalValue'>" + total + "</span>");
        groupTotalDisplay.append(newSpan);
    }
}
function calculateGroupTotal ( cellsToTotal , totalTd , groupTotalDiv , rowIndex , columnIndex ) { var total = 0 ; var values = new Array ( ) ; var hasInvalidValues = false ; var extraData = groupTotalDiv . data ( "params" ) ; var functionName = groupTotalDiv . data ( "function" ) ; for ( var i = 0 ; i < cellsToTotal . length ; i ++ ) { var currentCell = cellsToTotal [ i ] ; var isCellObject = currentCell != null && typeof currentCell === 'object' ; var value ; if ( isCellObject ) { value = currentCell . val ; if ( value == null ) { value = "" ; } } var isAddLine = ! isCellObject && currentCell && jQuery ( currentCell ) . find ( ":input[name^='newCollectionLines']" ) . length ; if ( ! isAddLine ) { value = coerceTableCellValue ( currentCell , true ) ; } else { continue ; } value = convertComplexNumericValue ( value ) ; if ( value == undefined || ( value && ! jQuery . isNumeric ( value ) ) ) { hasInvalidValues = true ; continue ; } if ( value != "" ) { value = parseFloat ( value ) ; values . push ( value ) ; } } if ( ! hasInvalidValues ) { if ( extraData != undefined ) { total = executeFunctionByName ( functionName , window , values , extraData ) ; } else { total = executeFunctionByName ( functionName , window , values ) ; } } else { total = "N/A" ; } var groupTotalDisplay = totalTd . find ( "[data-role='groupTotal'][data-function='" + functionName + "']" ) ; if ( groupTotalDisplay . length == 0 ) { groupTotalDisplay = groupTotalDiv . clone ( ) ; groupTotalDisplay = groupTotalDisplay . attr ( "id" , groupTotalDisplay . attr ( "id" ) + "_" + rowIndex + columnIndex ) ; groupTotalDisplay . find ( "[id]" ) . each ( function ( ) { jQuery ( this ) . attr ( "id" , jQuery ( this ) . attr ( "id" ) + "_" + rowIndex + columnIndex ) ; } ) ; totalTd . append ( groupTotalDisplay ) ; groupTotalDisplay . show ( ) ; } var totalValueSpan = groupTotalDisplay . find ( "[data-role='totalValue']" ) ; if ( totalValueSpan . length ) { totalValueSpan . html ( total ) ; } else { var newSpan = jQuery ( "<span data-role='totalValue'>" + total + "</span>" ) ; groupTotalDisplay . append ( newSpan ) ; } }
Calculates the group total and places it in the totalTd provided using a clone of the
Calculates the group total and places it in the totalTd provided using a clone of the
//check if cell is a cellObject - using mData setting
 // skip over add line
 //set hasInvalidValues to true if value is undefined
 //skip over value when blank
 //clone and append, if no place to display the total has been generated yet
 //resetting ids to unique ids on the clone
