Announcement

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

    Bugs related to ListGrid grouping

    Hi,

    I slightly modified the MultiGroupingSample.java Showcase example (latest SVN) to demonstrate what I believe are bugs in the current version.
    Here is the modified code:
    Code:
    package com.smartgwt.sample.showcase.client.grid.grouping;
    
    import java.util.HashMap;
    
    import com.google.gwt.i18n.client.NumberFormat;
    import com.smartgwt.client.data.DataSource;
    import com.smartgwt.client.types.Alignment;
    import com.smartgwt.client.types.ExpansionMode;
    import com.smartgwt.client.types.GroupStartOpen;
    import com.smartgwt.client.types.RecordSummaryFunctionType;
    import com.smartgwt.client.types.SortDirection;
    import com.smartgwt.client.types.SummaryFunctionType;
    import com.smartgwt.client.widgets.Canvas;
    import com.smartgwt.client.widgets.IButton;
    import com.smartgwt.client.widgets.UserFormula;
    import com.smartgwt.client.widgets.events.ClickEvent;
    import com.smartgwt.client.widgets.events.ClickHandler;
    import com.smartgwt.client.widgets.grid.CellFormatter;
    import com.smartgwt.client.widgets.grid.ListGrid;
    import com.smartgwt.client.widgets.grid.ListGridField;
    import com.smartgwt.client.widgets.grid.ListGridRecord;
    import com.smartgwt.client.widgets.grid.ListGridSummaryField;
    import com.smartgwt.sample.showcase.client.PanelFactory;
    import com.smartgwt.sample.showcase.client.ShowcasePanel;
    import com.smartgwt.sample.showcase.client.data.OrderItemLocalDS;
    
    public class MultiGroupingSample extends ShowcasePanel {
    
        private static final String DESCRIPTION =
            "<p>Grids support multiple levels of grouping, including a built-in dialog that " +
            "allows users to configure grouping.  This is enabled by a single setting: " + 
            "<code>canMultiGroup</code>." + 
            "<p>" + 
            "The grid below is grouped by Category, then by Ship Date.  Push the \"Configure Grouping\" " + 
            "button to launch a dialog for configuring multi-level grouping.  This can also be accessed " +
            "from the drop-down menu on any column header, via the \"Configure Grouping...\" menu item.";
    
        public static class Factory implements PanelFactory {
            private String id;
    
            public ShowcasePanel create() {
                MultiGroupingSample panel = new MultiGroupingSample();
                id = panel.getID();
                return panel;
            }
    
            public String getID() {
                return id;
            }
    
            public String getDescription() {
                return DESCRIPTION;
            }
        }
    
        public Canvas getViewPanel() {
            DataSource dataSource = OrderItemLocalDS.getInstance();
            
    		HashMap<String, String> formulaMapping =  new HashMap<String, String>();
    
            ListGridField orderIdField = new ListGridField("orderID");
            orderIdField.setIncludeInRecordSummary(false);
    
            ListGridField itemDescriptionField = new ListGridField("itemDescription");
    
            ListGridField categoryField = new ListGridField("category");
            ListGridField shipDateField = new ListGridField("shipDate");
            ListGridField quantityField = new ListGridField("quantity");
            ListGridField unitPriceField = new ListGridField("unitPrice");
    
            ListGridSummaryField totalField = new ListGridSummaryField("total", "Total");
            totalField.setAlign(Alignment.RIGHT);        
            totalField.setRecordSummaryFunction(RecordSummaryFunctionType.MULTIPLIER);
            totalField.setCellFormatter(new CellFormatter() {
                public String format(Object value, ListGridRecord record, int rowNum, int colNum) {
                    if (value == null) return null;
                    try {
                        NumberFormat nf = NumberFormat.getFormat("#,##0.00");
                        return "$" + nf.format(((Number) value).doubleValue());
                    } catch (Exception e) {
                        return value.toString();
                    }
                }
            });
            totalField.setSummaryFunction(SummaryFunctionType.SUM);
        	formulaMapping.put("T", "total");
            
            ListGridField countField = new ListGridField("count", "Count");
            countField.setUserFormula(new UserFormula("1"));
            countField.setSummaryFunction(SummaryFunctionType.SUM);
            countField.setApplyAfterSummary(false);
        	formulaMapping.put("C", "count");
        	
            ListGridField meanField = new ListGridField("mean", "Mean");
            meanField.setUserFormula(new UserFormula("T/C", formulaMapping));
            meanField.setShowGridSummary(true);
            meanField.setShowGroupSummary(true);
            meanField.setSummaryFunction(SummaryFunctionType.SUM);
            meanField.setApplyAfterSummary(true);
        	formulaMapping.put("M", "mean");
    
            final ListGrid listGrid = new ListGrid();
           
            listGrid.setWidth(600);
            listGrid.setHeight(500);
            listGrid.setAutoFetchData(true);
    
            listGrid.setShowAllRecords(true);
            listGrid.setDataSource(dataSource);
            listGrid.setCanEdit(true);
    
            listGrid.setGroupByField("category", "shipDate");
            listGrid.setGroupStartOpen(GroupStartOpen.ALL);
            listGrid.setCanMultiGroup(true);
    
            listGrid.setSortField("shipDate");
            listGrid.setSortDirection(SortDirection.ASCENDING);
    
            listGrid.setFields(orderIdField, itemDescriptionField, categoryField, shipDateField, 
                               quantityField, unitPriceField, totalField, countField, meanField);
    
            final IButton button = new IButton();
            button.setTop(525);
            button.setTitle("Configure Grouping");
            button.addClickHandler(new ClickHandler() {
                    public void onClick(ClickEvent event) {
                        listGrid.configureGrouping();
                    }
                });
    
            final Canvas canvas = new Canvas();
            listGrid.setShowGroupSummary(true);
            
            canvas.addChild(listGrid);
            canvas.addChild(button);
            return canvas;
        }
    
        public String getIntro() {
            return DESCRIPTION;
        }
    }
    First, summary values for the inner groups are missing (i.e. they are 0).
    Second, the setApplyAfterSummary(true) on the mean field does not do what I interpreted from the docs it would do.
    My expectation was it would calculate a value of 17500/5 for the mean column's outer summary value, but the value is shown as 17500.
    Third, if you scroll down the list until the end, suddenly all aggregated summary values in the count column that are hidden for a short time (out out visible area due to scrolling and get visible again) are reset to 1 (e.g. from 5 to 1).

    Regards,
    fatzopilot

    SmartClient Version: v10.1d_2014-07-31/LGPL Development Only (built 2014-07-31)
    GWT 2.5.1
    Chrome Version 36.0.1985.125 m (compiled mode)
    FF 26.0 (dev mode)
    Attached Files
    Last edited by fatzopilot; 6 Aug 2014, 00:25.

    #2
    We have reproduced the problem and are investigating.

    Comment


      #3
      This has been fixed in SGWT 5.1d/5.0d/4.1p and SC 10.1d/10.0d/9.1p. The fixes will be in the next nightly builds.

      Comment


        #4
        Hi,

        thanks for the fix.
        I found another issue:
        If a field that is used in a formula is initially hidden, the summarized value of the formula field is not calculated until the hidden field is shown.
        Just insert
        Code:
        countField.setHidden(true);
        to reproduce this.

        Regards,
        fatzopilot

        Comment


          #5
          We are able to reproduce this and we're looking into it.

          Comment


            #6
            This issue will be addressed in SC 10.0d/SGWT 5.0d and newer branches. The fix should be in the next nightlies for SC 10.0d/SGWT 5.0d, but it may be a bit longer for it to make it into SC 10.1d/SGWT 5.1d.

            Comment


              #7
              Works fine now on latest 5.1 as well.
              Thanks for the fix!

              Regards,
              fatzopilot

              Comment

              Working...
              X