Quantcast
Channel: SmartClient Forums
Viewing all articles
Browse latest Browse all 4756

applySummaryFunction not consistent with grid summary functions

$
0
0
SmartClient_v90p_2014-03-13_PowerEdition

This is related to post: http://forums.smartclient.com/showthread.php?t=26693

It seems like the summary functions have been updated (per the previous post) to correctly handle cases where there are dots "." in a formula field (divide by zero). I have tested this with the grid using summary functions.

However, in some cases we allow the user to add descriptive text to summary functions, so the display in the grid is more useful. For example a user may want to display the sum and average, so our application allows users to display the text "Total" and "Average" in the summary row, so the values are more descriptive. This is achieved using a custom function for the summary function. I have simplified the code for this test case to illustrate my point.

Repro steps:
- Load the test case
- The grid will display with a formula column (observations/inspections).
- Observe some rows have a divide by zero, resulting in "." for the formula value.
- I have added three sumamry functions to the grid, "sum", "avg" and "max", in that order.
- Observe that those values are 6, 3 and 6 respectively, which are correct.
- Open the browser console (Firefox). Note that the same summary calculations yield null.

It seems like isc.SimpleType.applySummaryFunction() has not been updated to behave the same as the built in grid summaries that were fixed (per the previous post).

Code:

<html>

        <head>
                <title >SNTQ-1843</title>
               
                <script type="text/javascript" >
                        var isomorphicDir="http://localhost:8080/isomorphic/";
                       
                        var data = [
                                { project:"Some zeros",  inspections:0, observations:0 },
                                { project:"Some zeros",  inspections:5, observations:0 },
                                { project:"Some zeros",  inspections:0, observations:0 },
                                { project:"Some zeros",  inspections:1, observations:6 }
                        ];
                </script>
               
                <script type="text/javascript" SRC="http://localhost:8080/isomorphic/system/development/ISC_Core.js"></script>
                <script type="text/javascript" SRC="http://localhost:8080/isomorphic/system/development/ISC_Foundation.js"></script>
                <script type="text/javascript" SRC="http://localhost:8080/isomorphic/system/development/ISC_Containers.js"></script>
                <script type="text/javascript" SRC="http://localhost:8080/isomorphic/system/development/ISC_Grids.js"></script>
                <script type="text/javascript" SRC="http://localhost:8080/isomorphic/system/development/ISC_Forms.js"></script>
                <script type="text/javascript" SRC="http://localhost:8080/isomorphic/system/development/ISC_DataBinding.js"></script>
                <script type="text/javascript" SRC="http://localhost:8080/isomorphic/system/development/ISC_Drawing.js"></script>
                <script type="text/javascript" SRC="http://localhost:8080/isomorphic/system/development/ISC_PluginBridges.js"></script>
                <script type="text/javascript" SRC="http://localhost:8080/isomorphic/system/development/ISC_Charts.js"></script>
                <script type="text/javascript" SRC="http://localhost:8080/isomorphic/system/development/ISC_Tools.js"></script>
                <script type="text/javascript" SRC="http://localhost:8080/isomorphic/skins/EnterpriseBlue/load_skin.js"></script>
        </head>
<body>

        <script type="text/javascript">

                var gridObject = isc.ListGrid.create({
                        fields:[
                                {name:"project", title:"Project", type:"text" },
                                {name:"formula", title: "Formula", userFormula: { formulaVars: {A:"observations", B:"inspections"}, text:"A/B" }, summaryFunction :["sum", "avg", "max"] },
                                {name:"inspections", type:"integer", title:"# Inspections"},
                                {name:"observations", type:"integer",  title:"# Observations"}
                        ],
                                dataFetchMode : "local",
                                data: data,
                                width : "100%",
                                align : "center",
                                autoFitData : "vertical",
                                autoFitMaxHeight : 400,
                                alternateRecordStyles : true,
                                canAddFormulaFields : true,
                                canAddSummaryFields : true,
                                canGroupBy : true,
                                canReorderFields : true,
                                showGridSummary : true,
                                useAdvancedFieldPicker : true,
                                advancedFieldPickerThreshold : 2
                });
                       
                var aggregateFunction = function(records, summaryField, f, t) {
               
                        var val = isc.SimpleType.applySummaryFunction(records, gridObject.getField(summaryField), f);
                        if (typeof (val) != "undefined" && val != null) {
                                return t + val;
                        }
                        else {
                                return t + "null";
                        }
                }

                // set the summary functions for this formula
                console.log("formula field summary function values");
                console.log(aggregateFunction(gridObject.data, "formula", "sum", "=== Total is "));
                console.log(aggregateFunction(gridObject.data, "formula", "avg", "=== Average is "));
                console.log(aggregateFunction(gridObject.data, "formula", "max", "=== Maximum is "));
                                       
        </script>       

</body>
</html>


Viewing all articles
Browse latest Browse all 4756

Trending Articles