Announcement

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

    Best practice: Showing hidden groupBy column when no. of records>groupByMaxRecords()

    Hi Isomorphic,

    how is this usecase best solved (using current 5.0p, v10.0p_2015-10-08):

    I have a ListGrid displaying many columns, therefore width is valueable.
    I have a column that is always grouped and has useful information in the groupHeader, but also the group value. Therefore I hide the column itself. Now, if the data returned is more than setGroupByMaxRecords(), I have the problem that the informational groupHeader is not shown, but the column itself with its data is still hidden.
    I tried addGroupByCompleteHandler and addGroupByHandler, where I assume that the former is the correct one. At least it fires asynchronously after grouping is complete on the client. It does not fire if the grouping does not take place because of the total number of records being larger than setGroupByMaxRecords() (see test case).

    How do I notice best that I need to programmatically show the column? Can you make addGroupByCompleteHandler fire as well when grouping is unsuccessful (perhaps with some value parameter that grouping was unsuccessful)?
    Should I use addDataArrivedHandler() and look at the total ResultSet length?

    Code:
    package com.smartgwt.sample.client;
    
    import com.google.gwt.core.client.EntryPoint;
    import com.smartgwt.client.core.KeyIdentifier;
    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.grid.ListGrid;
    import com.smartgwt.client.widgets.grid.ListGridField;
    import com.smartgwt.client.widgets.grid.events.GroupByCompleteEvent;
    import com.smartgwt.client.widgets.grid.events.GroupByCompleteHandler;
    import com.smartgwt.client.widgets.grid.events.GroupByEvent;
    import com.smartgwt.client.widgets.grid.events.GroupByHandler;
    
    public class BuiltInDS implements EntryPoint {
        private IButton recreateBtn;
        private DataSource supplyItemDS = DataSource.get("supplyItem");
    
        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();
                }
            });
    
            recreateBtn = new IButton("Recreate");
            recreateBtn.addClickHandler(new ClickHandler() {
                @Override
                public void onClick(ClickEvent event) {
                    recreate();
                }
            });
            recreate();
            recreateBtn.draw();
        }
    
        private void recreate() {
            Window w = new Window();
            w.setWidth("95%");
            w.setHeight("95%");
            w.setMembersMargin(0);
            w.setModalMaskOpacity(70);
            w.setTitle("Grouping test");
            w.setShowMinimizeButton(false);
            w.setIsModal(true);
            w.setShowModalMask(true);
            w.centerInPage();
    
            ListGrid lg = new ListGrid(supplyItemDS);
            lg.setCanEdit(false);
            lg.setCanGroupBy(false);
            lg.setGroupByMaxRecords(90);
            lg.setAllowFilterExpressions(true);
            lg.setShowFilterEditor(true);
            lg.setAutoFetchData(false);
            lg.setGroupStartOpen(GroupStartOpen.ALL);
            lg.setCanGroupBy(true);
            lg.setCanReorderFields(true);
    
            ListGridField itemIdLGF = new ListGridField("itemID");
            ListGridField itemNameLGF = new ListGridField("itemName");
            ListGridField skuLGF = new ListGridField("SKU");
            ListGridField descriptionLGF = new ListGridField("description");
            ListGridField categoryLGF = new ListGridField("category");
            categoryLGF.setHidden(true);
            categoryLGF.setCanHide(false);
            ListGridField unitsLGF = new ListGridField("units");
    
            lg.setSortByGroupFirst(true);
            lg.setGroupByField(categoryLGF.getName());
    
            lg.setFields(itemIdLGF, itemNameLGF, skuLGF, descriptionLGF, categoryLGF, unitsLGF);
    
            lg.setSort(new SortSpecifier[] { new SortSpecifier(itemIdLGF.getName(), SortDirection.ASCENDING),
                    new SortSpecifier(itemNameLGF.getName(), SortDirection.ASCENDING) });
    
            lg.addGroupByCompleteHandler(new GroupByCompleteHandler() {
                @Override
                public void onGroupByComplete(GroupByCompleteEvent event) {
                    SC.logWarn("GroupByCompleteHandler: " + event.toDebugString());
                }
            });
    
            lg.addGroupByHandler(new GroupByHandler() {
                @Override
                public void onGroupBy(GroupByEvent event) {
                    SC.logWarn("GroupByHandler: " + event.toDebugString());
                }
            });
    
            lg.fetchData(new Criterion(itemIdLGF.getName(), OperatorId.LESS_OR_EQUAL, 100));
    
            w.addItem(lg);
            w.show();
        }
    }
    Thank you & Best regards
    Blama

    #2
    I'm just seeing that there already is GroupByCompleteEvent.getFields(). Now, if the event would fire with an empty list if grouping is unsuccessful, I could show() the field then.

    Best regards
    Blama

    Comment


      #3
      This actually should be working. We are looking into it. It's quite likely this is related to the other report you filed about list grids with too many records to group (and asynchronous grouping) sometimes showing the grouping prompt and then failing to actually build a working group-tree.

      Anyway we'll follow up when we have more info

      Regards
      Isomorphic Software

      Comment


        #4
        Sorry for the long pause on this. We have now made a change to address this. The groupByComplete handler will fire in the case where grouping was attempted but failed due to the data exceeding the maxGroupByRecords count. The 'fields' parameter for the callback will be an empty array in this case. We've made this change in 5.0 and 5.1 branches. It should show up in the next nightly builds (Nov 7 or greater)

        Regards
        Isomorphic Software

        Comment

        Working...
        X