Announcement

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

    Small Grouped Listgrid setGroupTitleRenderer groupNode.getGroupMembers() question

    Hi Isomorphic,

    please run this sample (v10.1p_2017-03-02).
    As you can see, the number for the group nodes is one more than expected for each male/female. This is because the groupSummaryRow is included in groupNode.getGroupMembers(). Is this expected?
    Code:
    package com.smartgwt.sample.client;
    
    import com.google.gwt.core.client.EntryPoint;
    import com.smartgwt.client.Version;
    import com.smartgwt.client.core.KeyIdentifier;
    import com.smartgwt.client.data.AdvancedCriteria;
    import com.smartgwt.client.data.Criterion;
    import com.smartgwt.client.data.DataSource;
    import com.smartgwt.client.data.SortSpecifier;
    import com.smartgwt.client.types.GroupStartOpen;
    import com.smartgwt.client.types.OperatorId;
    import com.smartgwt.client.types.SortDirection;
    import com.smartgwt.client.util.Page;
    import com.smartgwt.client.util.PageKeyHandler;
    import com.smartgwt.client.util.SC;
    import com.smartgwt.client.widgets.IButton;
    import com.smartgwt.client.widgets.Window;
    import com.smartgwt.client.widgets.events.ClickEvent;
    import com.smartgwt.client.widgets.events.ClickHandler;
    import com.smartgwt.client.widgets.form.fields.ComboBoxItem;
    import com.smartgwt.client.widgets.grid.GroupNode;
    import com.smartgwt.client.widgets.grid.GroupTitleRenderer;
    import com.smartgwt.client.widgets.grid.ListGrid;
    import com.smartgwt.client.widgets.grid.ListGridField;
    import com.smartgwt.client.widgets.layout.VLayout;
    
    public class BuiltInDS implements EntryPoint {
        private VLayout mainLayout;
        private IButton recreateBtn;
    
        public void onModuleLoad() {
            KeyIdentifier debugKey = new KeyIdentifier();
            debugKey.setCtrlKey(true);
            debugKey.setKeyName("D");
    
            Page.registerKey(debugKey, new PageKeyHandler() {
                public void execute(String keyName) {
                    SC.showConsole();
                }
            });
    
            mainLayout = new VLayout(20);
            mainLayout.setWidth100();
            mainLayout.setHeight100();
    
            recreateBtn = new IButton("Recreate");
            recreateBtn.addClickHandler(new ClickHandler() {
                @Override
                public void onClick(ClickEvent event) {
                    recreate();
                }
            });
            mainLayout.addMember(recreateBtn);
            recreate();
            mainLayout.draw();
        }
    
        private void recreate() {
            Window w = new Window();
            w.setWidth("95%");
            w.setHeight("95%");
            w.setMembersMargin(0);
            w.setModalMaskOpacity(70);
            w.setTitle(" (" + Version.getVersion() + "/" + Version.getSCVersionNumber() + ")");
            w.setTitle("TITLE" + w.getTitle());
            w.setShowMinimizeButton(false);
            w.setIsModal(true);
            w.setShowModalMask(true);
            w.centerInPage();
    
            final ListGrid employeesGrid = new ListGrid();
    
            employeesGrid.setHeight100();
            employeesGrid.setAutoFetchData(false);
            employeesGrid.setCanEdit(true);
            employeesGrid.setDataSource(DataSource.get("employees"));
            employeesGrid.setCanGroupBy(true);
            employeesGrid.setGroupStartOpen(GroupStartOpen.ALL);
    
            ListGridField employeeId = new ListGridField("EmployeeId");
            employeeId.setCanEdit(false);
    
            ListGridField name = new ListGridField("Name");
            name.setCanEdit(false);
    
            ListGridField gender = new ListGridField("Gender");
            gender.setGroupTitleRenderer(new GroupTitleRenderer() {
                public String getGroupTitle(Object groupValue, GroupNode groupNode, ListGridField field, String fieldName, ListGrid grid) {
                    return (String) groupValue + " (" + groupNode.getGroupMembers().length + ")";
                }
            });
            gender.setCanGroupBy(true);
            employeesGrid.setShowGridSummary(true);
    
            // Enable/Disable this row
            employeesGrid.setShowGroupSummary(true);
    
            ListGridField reportsTo = new ListGridFieldReportsTo("ReportsTo");
            reportsTo.setHidden(false);
    
            ListGridField job = new ListGridField("Job");
    
            employeesGrid.setFields(employeeId, name, gender, reportsTo, job);
            employeesGrid.setSort(new SortSpecifier[] { new SortSpecifier(name.getName(), SortDirection.ASCENDING) });
            employeesGrid.setGroupByField(gender.getName());
            employeesGrid.fetchData(new AdvancedCriteria(new Criterion(name.getName(), OperatorId.STARTS_WITH, "Ab")));
            w.addItem(employeesGrid);
            w.show();
        }
    
        private class ListGridFieldReportsTo extends ListGridField {
            public ListGridFieldReportsTo(String name) {
                super(name);
                ComboBoxItem managerCBI = new ComboBoxItem();
                managerCBI.setOptionDataSource(DataSource.get("employees"));
                managerCBI.setOptionOperationId("foobar");
                managerCBI.setValueField(DataSource.get("employees").getPrimaryKeyFieldName());
                managerCBI.setDisplayField("Name");
                managerCBI.setPickListSort(new SortSpecifier[] { new SortSpecifier("EmployeeId", SortDirection.ASCENDING),
                        new SortSpecifier("Name", SortDirection.ASCENDING) });
                ListGridField managerCBI_empIdLGF = new ListGridField("EmployeeId");
                ListGridField managerCBI_nameLGF = new ListGridField("Name");
                managerCBI.setPickListFields(managerCBI_empIdLGF, managerCBI_nameLGF);
                managerCBI.setPickListHeaderHeight(0);
                setEditorProperties(managerCBI);
            }
        }
    }
    If it is expected, this heals it for me, but I'm not sure I should need to fix it in the 1st place:
    Code:
            gender.setGroupTitleRenderer(new GroupTitleRenderer() {
                public String getGroupTitle(Object groupValue, GroupNode groupNode, ListGridField field, String fieldName, ListGrid grid) {
                    return (String) groupValue + " (" + [B](groupNode.getGroupMembers().length - (grid.getShowGroupSummary() ? 1 : 0))[/B] + ")";
                }
            });
    Also, as convenience you could disable creating a default summaryFuntion for integer fields, if the field is a PK or FK field. I'm pretty sure generating it is wrong more often than it is correct.

    Best regards
    Blama

    #2
    Hi Isomorphic,

    it gets even more complicated with Multigrouping.
    Can you show GroupTitleRenderer-code that counts the real ListGrid rows in grouped and multigrouped grids?

    Thank you & Best regards
    Blama

    Comment


      #3
      We've made some improvements in SGWT 6.1d to this area:
      • GroupNode has been moved underneath TreeNode, and GroupSummary under ListGridRecord
      • GroupNode.getGroupMembers() has been deprecated in favor of ListGrid.getGroupMembers(). The new method returns an array of ListGridRecord whose elements are appropriately subtyped, and has a parameter to control whether you get back all of the immediate children (including both other group nodes when multi-grouping and summary records) or all descendants that are real ListGrid records (no group nodes or summary records).
      • You can either use instanceof to classify a given ListGridRecord, or ListGrid APIs such as ListGrid.isGroupNode() and ListGrid.isSummaryRecord().



      Comment


        #4
        Hi Isomorphic,

        thanks a lot, those changes really make it easy working with GroupTitleRenderer.

        Best regards
        Blama

        Comment


          #5
          Hi Isomorphic,

          I get this entry in the logs now for every grouped ListGrid:
          Code:
          18:29:05.019:MUP1:WARN:ListGrid:ListGrid_abc:The groupNode passed to getGroupMembers() isn't from this grid
          This is my GroupTitleRenderer class:
          Code:
          public final class DefaultGroupTitleRenderer implements GroupTitleRenderer {
              private String oneItem;
              private String notOneItem;
          
              public DefaultGroupTitleRenderer() {
                  this(null, null);
              }
          
              public DefaultGroupTitleRenderer(String oneItem, String notOneItem) {
                  super();
                  this.oneItem = oneItem;
                  this.notOneItem = notOneItem;
              }
          
              public String getGroupTitle(Object groupValue, GroupNode groupNode, ListGridField field, String fieldName, ListGrid grid) {
                  if (groupValue == null)
                      return null;
          
                  String retVal = groupValue.toString();
                  int groupSize = grid.getGroupMembers(groupNode, true).length;
                  if (oneItem != null && notOneItem != null) {
                      retVal += " (" + groupSize + " " + ((groupSize == 1) ? oneItem : notOneItem) + ")";
                  } else {
                      retVal += " (" + groupSize + ")";
                  }
          
                  return retVal;
              }
          }
          Best regards
          Blama

          Comment


            #6
            Using the snippets of code you provided, there is no warning upon the initial draw, but we did see an issue when the grid is regrouped, and that will be fixed in the nightly builds dated 2017-04-16 and beyond. If you still see an issue, you'll have to provide more details about exactly what you're doing.

            Comment


              #7
              Hi Isomorphic,

              the warning disappeared using SNAPSHOT_v11.1d_2017-04-16.

              Thank you
              Blama

              Comment

              Working...
              X