Announcement

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

    Grouped LG: sortBy field not used in DSRequest when not setting displayField in Java

    Hi Isomorphic,

    please see this v10.1p_2015-12-18/PowerEdition BuiltInDS-based testcase:

    BuiltInDS.java:
    Code:
    package com.smartgwt.sample.client;
    
    import com.google.gwt.core.client.EntryPoint;
    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.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("Grouped ListGrid: Sort-By field not used in DSRequest when not setting displayField again in Java.");
            w.setShowMinimizeButton(false);
            w.setIsModal(true);
            w.setShowModalMask(true);
            w.centerInPage();
    
            final ListGrid supplyItem = new ListGrid();
            supplyItem.setHeight100();
            supplyItem.setAutoFetchData(false);
            supplyItem.setSortByGroupFirst(true);
    
            supplyItem.setDataSource(DataSource.get("supplyItem"));
            supplyItem.setGroupStartOpen(GroupStartOpen.ALL);
            supplyItem.setGroupSortDirection(SortDirection.ASCENDING);
            supplyItem.setGroupByField("category");
    
            ListGridField category = new ListGridField("category");
            ListGridField itemID = new ListGridField("itemID");
            /*
             With this line, the RPC Request contains "itemName" as 2nd sortfield.
             Without this line, the RPC Request contains neither "itemName" nor "itemID" as 2nd sortfield.
             */
            // itemID.setDisplayField("itemName");
            ListGridField SKU = new ListGridField("SKU");
            ListGridField description = new ListGridField("description");
    
            supplyItem.setFields(category, itemID, SKU, description);
    
            // No difference if setSortState or setSort is used.
            // supplyItem
            // .setSortState("({fieldName:\"itemID\",sortDir:\"ascending\",sortSpecifiers:[{property:\"itemID\",direction:\"ascending\"}]})");
            supplyItem.setSort(new SortSpecifier[] { new SortSpecifier(itemID.getName(), SortDirection.ASCENDING) });
            supplyItem.fetchData(new AdvancedCriteria(new Criterion("itemName", OperatorId.STARTS_WITH, "Acc")));
            w.addItem(supplyItem);
    
            IButton reloadBtn = new IButton("Reload data");
            reloadBtn.addClickHandler(new ClickHandler() {
                @Override
                public void onClick(ClickEvent event) {
                    supplyItem.invalidateCache();
                }
            });
            w.addItem(reloadBtn);
    
            w.show();
        }
    }
    supplyItem.ds.xml:
    Code:
    Please add this to field "itemID" in supplyItem.ds.xml: displayField="itemName"[B][/B]
    1. When you open the application, you'll see that the data loads, but is only sorted by the setSortByGroupFirst-groupBy-field in the DSRequest. (One field missing)
    2. If you click "Reload data", the data is requested again, but this time sorted by category and itemID(->itemName) (OK)
    3. If you enable row itemID.setDisplayField("itemName"); and reopen the window, the data is requested sorted by category and itemID(->itemName) (OK)
    4. If you disable itemID.setDisplayField("itemName"); again and also disable supplyItem.setGroupByField("category");, the data is loaded sorted by itemID(->itemName) (OK)

    So the error is only occuring in a grouped ListGrid with a field, where the displayField is only set in .ds.xml.
    I'm not sure if this is also related to the type of the field/displayField.

    Tested in GC47 Compiled and FF26 Dev Mode.



    Best regards
    Blama

    #2
    Hi Blama,

    We do see what's going on here.
    Before we get into that: our first question to you would be - are you seeing actual user-visible ill effects from this behavior?
    In your test we do see the initial request hit the server with just "Category" specified - but the data is correctly sorted by both fields on the client once displayed to the user.

    Do you have a case where you're actually ending up with incorrect sort in the data displayed to the user?

    In terms of the underlying issue - in the ListGrid we delay "binding" the grid to its dataSource until right before it is drawn by default.
    This means that the merging of field properties from the DataSource definition with the properties defined directly on the ListGrid doesn't happen immediately when the grid is created.
    In your usage, you're calling fetchData on the grid before draw, and before this "binding" has occurred. As a result the grid is unaware of the displayField setting when the initial fetch occurs, so the sort information isn't sent down as part of that fetch.

    We're looking into whether it would make sense to have the fetch itself trigger the binding of fields - which would get rid of this behavior where that sort specifier was ignored.

    However, there's also logic in place to re-apply the sort on the client side when the binding does occur, which appears to correctly ensure the user is actually presented with properly sorted data, at least in this test case, so it would be good to know if you're seeing a problem with this.

    Thanks
    Isomorphic Software


    Comment


      #3
      A follow up on this: With a little more investigation we realized we could handle this case better automatically.
      We've made a change to 10.1p / 11.0d which should ensure that the server fetch has the correct criteria from the get-go in your usage. Please give it a try and let us know if you continue to see this.

      Also we'd still be interested in knowing whether you were actually seeing wrongly sorted data displayed to the user, or whether this was simply an observation about the sort-specification sent to the server.
      If the former, there may be more investigation to do here, so we'd like to know what the (user-visible) problem you encountered looked like.

      Thanks
      Isomorphic Software

      Comment


        #4
        Hi Isomorphic,

        I'm not sure if I saw an incorrect result - I noted the missing sort-specification when testing for the other thread in that area.
        I'll have look tomorrow.

        Best regards
        Blama

        Comment


          #5
          Hi Isomorphic,

          I don't see an erroneous behavior - The ListGrid requests all records up to setGroupByMaxRecords() - therefore it has all records and can do a sort on the full data.
          If the criteria will return more records than setGroupByMaxRecords(), a correct request for 0...75 (sorted by itemName) is issued.

          If it did not request the data sorted or did not request all data, this would lead to problems, as the client side resort of new incoming data when scrolling down would insert records "mid-grid" instead of "end-of-grid".

          So no, I don't see a problem currently with v10.1p_2016-01-03. But I'll try with your change from #3 nevertheless.

          Best regards
          Blama

          Comment


            #6
            Hi Isomorphic,

            a quick test with v10.1p_2016-01-07/PowerEdition Deployment shows that your change solves the problem for me in the testcase and in my application.

            Thank you & Best regards
            Blama

            Comment

            Working...
            X