Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    Discrepancy between grid summary and group summary formatting

    Hi,

    We are seeing a discrepancy between grid summary and group summary formatting. Is it possible to make the group summary formatting the same as the grid summary formatting?

    To see the difference, apply the code below to this example:
    http://www.smartclient.com/docs/8.2/a/system/reference/SmartClient_Explorer.html#summaryGrid

    Then look at the Unit Price column and see the Grid Summary is blank while the Group Summary shows NA. We'd prefer to show blank in both cases.



    Code:
    
    isc.ListGrid.create({
        ID: "companyList",
        width:600, height:520,
        alternateRecordStyles:true,
        autoFetchData:true,
        dataSource:orderItemLocalDS,
        showAllRecords:true,
        groupByField:"category", groupStartOpen:"all",
        canEdit:true, editEvent:"click",
        
        showGridSummary:true,
        showGroupSummary:true,
        fields:[
            {name:"orderID", includeInRecordSummary:false, summaryFunction:"count"},
            {name:"itemDescription"},
            {name:"category", showGridSummary:true, 
                getGridSummary:function (records, summaryField) {
                    var seenCategories = {};
                    for (var i = 0; i < records.length; i++) {
                        seenCategories[records[i].category] = true;
                    }
                    var totalCategories = isc.getKeys(seenCategories).length;
                    return totalCategories + " Categories";
                    
                }
            },
            {name:"shipDate", showGroupSummary:true, showGridSummary:false, summaryFunction:"max"},
            
            {name:"quantity", showGroupSummary:false, showGridSummary:false},
            {name:"unitPrice", showGroupSummary:true, showGridSummary:true,
             formatCellValue:function (value) {
                 if (isc.isA.Number(value)) {
                    return value.toCurrencyString("$");
                 }
                 return "NA";
             },
            summaryFunction:"return null;"
            },
            {name:"Total", type:"summary", recordSummaryFunction:"multiplier",
             summaryFunction:"sum",
             showGridSummary:true, showGroupSummary:true,
             align:"right",
             formatCellValue:function (value) {
                 if (isc.isA.Number(value)) {
                    return value.toCurrencyString("$");
                 }
                 return value;
             }
            }
        ]
    })

    #2
    Might that be the wrong URL? None of the unitPrice values are missing, so there are no blanks, and the data cannot be edited in the sample.

    You may have meant a different sample where "NA" shows because, in the sample code, emptyCellValue has been set to "NA" (so that's how you control this).

    Comment


      #3
      No, that is the right URL. I just double-checked everything. When you use the code I pasted, the group summaries for Unit Price show as NA but the Grid Summary for Unit Price at the very bottom shows as blank.

      I'm trying to get grid summaries and group summaries to show up the same in that case.

      Comment


        #4
        You realize that the code you posted explicitly returns the string "NA" in one case, but not the other?

        Comment


          #5
          Are you saying that summaryFunction:"return null;" forces the grid summary to return null but doesn't have the same effect on the group summary? If so, why not? How do I make them consistent?

          Comment


            #6
            There's a pipeline of operations on the value - summaries are computed and then formatters are applied. You're returning null from the summary function, then transforming that to an "NA" via your formatCellValue. Then, your other formatCellValue implementation differs, and does not do this.

            Comment


              #7
              Sorry, I don't follow that completely. I only have one formatCellValue method for the column we are discussing which is Unit price. So, is there another one that I'm missing? I'm not clear on what I need to do so that the group summary for Unit Price displays the same as the Grid Summary. Can you provide a suggestion on how I can make them the same?

              Comment


                #8
                OK the code above has "return NA" and you've said you want blank instead. Removing "return NA" would do that.

                Comment


                  #9
                  I want the individual cells in the grid to show NA but I want the summary values (both the grid summary and the group summary ) to show blank. I thought that using summaryFunction:"return null;" would cause both the grid summary and the group summary for Unit Price to show as null. But, the group summary is showing NA and the grid summary is showing blank. Why is the summaryFunction:" return null" not being applied to the group summary but is being applied to the grid summary?

                  Comment


                    #10
                    There is a separate listGridField.formatGridSummary if you want different handling for null in these two areas.

                    Comment


                      #11
                      I cannot get this to work the way I want after much trial and error. I want the grid summary and the group summary to be handled the exact same way.

                      I am happy with the way the grid summary is formatted. It is showing blank. But, it seems like the group summary is controlled by formatCellValue. I tried using formatGroupSummary like you see in the code below. But, it isn't having any effect. So, how can I have a summary function on the Unit Price column in this example that returns a blank instead of an NA for the group summary? Am I doing something wrong in the way I'm trying to use formatGroupSummary? To me, it seems like the group summary is tied to formatCellValue whereas the grid summary is not.

                      I hope you understand I have simplified my example from our production application to provide you a simple test case. We want to define a summary function for every column. But, we want the summary function to show a blank value even if formatCellValue shows an NA for the individual cells. And, we want it to work consistently between the group summaries and the grid summaries.

                      Code:
                      isc.ListGrid.create({
                          ID: "companyList",
                          width:600, height:520,
                          alternateRecordStyles:true,
                          autoFetchData:true,
                          dataSource:orderItemLocalDS,
                          showAllRecords:true,
                          groupByField:"category", groupStartOpen:"all",
                          canEdit:true, editEvent:"click",
                          
                          showGridSummary:true,
                          showGroupSummary:true,
                          fields:[
                              {name:"orderID", includeInRecordSummary:false, summaryFunction:"count"},
                              {name:"itemDescription"},
                              {name:"category", showGridSummary:true, 
                                  getGridSummary:function (records, summaryField) {
                                      var seenCategories = {};
                                      for (var i = 0; i < records.length; i++) {
                                          seenCategories[records[i].category] = true;
                                      }
                                      var totalCategories = isc.getKeys(seenCategories).length;
                                      return totalCategories + " Categories";
                                      
                                  }
                              },
                              {name:"shipDate", showGroupSummary:true, showGridSummary:false, summaryFunction:"max"},
                              
                              {name:"quantity", showGroupSummary:false, showGridSummary:false},
                              {name:"unitPrice", showGroupSummary:true, showGridSummary:true,
                               formatCellValue:function (value) {
                                   if (isc.isA.Number(value)) {
                                      return value.toCurrencyString("$");
                                   }
                                   return "NA";
                               },
                               formatGroupSummary:function (value) {
                                   if (isc.isA.Number(value)) {
                                      return value.toCurrencyString("$");
                                   }
                                   return null;
                               },
                              summaryFunction:"return null"
                              },
                              {name:"Total", type:"summary", recordSummaryFunction:"multiplier",
                               summaryFunction:"sum",
                               showGridSummary:true, showGroupSummary:true,
                               align:"right",
                               formatCellValue:function (value) {
                                   if (isc.isA.Number(value)) {
                                      return value.toCurrencyString("$");
                                   }
                                   return value;
                               }
                              }
                          ]
                      })

                      Comment


                        #12
                        We see the discrepancy. The issue is basically that when a group-summary row has a calculated value of 'null', it applies the invalidSummaryValue to the cell, but then runs the standard 'formatCellValue()' method on top of that, whereas when a grid summary has a calculated value of null it does not run through formatCellValue(). Clearly the behavior should be the same in both cases. We're looking at how best to resolve this in the code.

                        However for now the easiest way to get things running will be to modify your formatter to handle being passed a group, or grid summary row:
                        Code:
                                {name:"unitPrice", showGroupSummary:true, showGridSummary:true,
                                 formatCellValue:function (value, record, rowNum, colNum, grid) {
                                     if (isc.isA.Number(value)) {
                                        return value.toCurrencyString("$");
                                     }
                                     if (record.isGroupSummary || record.isGridSummary) return "&nbsp;";
                                     return "NA";
                                 },
                                summaryFunction:"return null"
                                },

                        Comment


                          #13
                          Thank you. That tweak will work for now.

                          Comment


                            #14
                            A quick update to let you know that we've resolved these discrepancies in the 8.3d branch.
                            However the change we made to get this working, while not drastic, is moderately involved and given that the solution suggested here should work for you we don't plan to immediately port across to 8.2p.

                            If this is going to prove unacceptable (for example you find you can't get the behavior you need out of 8.2 after all), let us know and we'll update 8.2

                            Comment


                              #15
                              Thanks for the update. I believe the workaround is sufficient for me so no need to port to 8.2.

                              Comment

                              Working...
                              X