Announcement

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

    SelectItem in ListGrid filterRow operatorId anomality

    Hi Isomorphic,

    please see this BuiltInDS based testcase (v10.1p_2015-12-18).

    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.DataSource;
    import com.smartgwt.client.types.OperatorId;
    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.SelectItem;
    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 ListGrid lg;
        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("SelectItem Criteria operatorId");
            w.setShowMinimizeButton(false);
            w.setIsModal(true);
            w.setShowModalMask(true);
            w.centerInPage();
    
            lg = new ListGrid(DataSource.get("employees"));
            lg.setAutoFetchData(true);
            lg.setShowFilterEditor(true);
    
            ListGridField Name = new ListGridField("Name");
            ListGridField EmployeeId = new ListGridField("EmployeeId");
            ListGridField Job = new ListGridField("Job");
            ListGridField Email = new ListGridField("Email");
            ListGridField EmployeeType = new ListGridField("EmployeeType");
            ListGridField Gender = new ListGridField("Gender");
            ListGridField MaritalStatus = new ListGridField("MaritalStatus");
    
            SelectItem props = new SelectItem();
            props.setOperator(OperatorId.EQUALS);
            Gender.setFilterEditorProperties(props);
    
            lg.setFields(Name, EmployeeId, Job, Email, EmployeeType, Gender, MaritalStatus);
    
            IButton sayCrits = new IButton("Show filterRow Criteria", new ClickHandler() {
                @Override
                public void onClick(ClickEvent event) {
                    SC.say("WITH PROPS", lg.getFilterEditorCriteria().asAdvancedCriteria().asString());
                }
            });
            sayCrits.setWidth(250);
    
            w.addItem(lg);
            w.addItem(sayCrits);
            w.show();
        }
    }[B][/B]


    Trying with and without Gender.setFilterEditorProperties(props); will give you the result from the screenshot:
    Click image for larger version

Name:	Operators.png
Views:	66
Size:	20.5 KB
ID:	233658

    My expectation would be that as the generated item is a SelectItem and not a ComboBoxItem or TextItem, that the used operator is "equals" by default. This is not true, but could be seen as minor enhancement, only.
    What I do not understand is that the operatorId used for "MaritalStatus" changes once I change the operatorId for "Gender".

    This has no priority for me, I just noticed it while creating an other testcase.

    Best regards
    Blama

    #2
    That's a strange effect, but, what if you use the documented way to do this: listGridField.filterOperator?

    Comment


      #3
      Hi Isomorphic,

      with Gender.setFilterOperator(OperatorId.EQUALS) the effect is the same. equals is used for both fields.

      Best regards
      Blama

      Comment


        #4
        Hi Blama
        After looking into this it actually makes sense.
        "Equals" is the correct (default) criteria operator for these fields - this is determined by the fact that these fields provide a limited set of options (an enum, thanks to the valueMap).

        Without the 'setFilterOperator' call, if you called 'lg.getFilterEditorCriteriaAsAdvancedCriteria()' you would get back 'equals' rather than 'iContains' operators for these fields.

        When you call getFilterEditorCriteria(), the object returned is a simple criteria, so the per field operators are not explicitly listed out.

        If you call 'asAdvancedCriteria()' directly on this object, the dataSource field definition is unavailable to the conversion code, so the default operator of iContains is used, and these "equals" operators are lost.

        If as an alternative, you had used the more sophisticated method on the DataSource itself: DataSource.get("employees").convertDataSourceCriteria(lg.getFilterEditorCriteria()).asString(), you'll see the 'equals' operator is picked up - this method is run on the dataSource and is aware that both these fields are enums.

        In the alternate case, where you call setFilterOperator() on one the fields, you essentially force the widget to always produce advanced criteria directly, so you always get the (correct) default operator of "equals" showing up.

        Hopefully this makes sense. Please let us know if you continue to have problems in this area

        Regards
        Isomorphic Software

        Comment

        Working...
        X