Announcement

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

  • ListGrid converts Set-Criteria to Or-Array of iContains-Criteria

    Hi Isomorphic,

    I noticed this issue in my application (testcase on v10.1p_2017-10-05). For me it has not the same severity as in the showcase where "Endangered" iContains-matches "Not endangered".

    It seems that ListGridField can accept and silently convert Set-Criteria to "Or-Criteria with iContains". But Set-Criteria are basically "Or-Criteria with equals".

    In my application I save the ListGrid filterState and for me the same thing happens. While I'm pretty sure that the application-issue is easy to solve via si.setOperator(OperatorId.IN_SET) (see the AnimalsFilterTest-code), this might be wrong anyway with respect to the default SelectItem.setCriterionSetter() implementation (not sure though).

    BuiltInDS-based Testcase:
    Code:
    package com.smartgwt.sample.client;
    
    import java.util.LinkedHashMap;
    
    import com.google.gwt.core.client.EntryPoint;
    import com.smartgwt.client.Version;
    import com.smartgwt.client.core.KeyIdentifier;
    import com.smartgwt.client.data.DataSource;
    import com.smartgwt.client.data.RecordList;
    import com.smartgwt.client.types.AutoFitWidthApproach;
    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.DynamicForm;
    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 extends VLayout implements EntryPoint {
        private IButton recreateBtn;
        private ListGrid lg;
    
        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();
                }
            });
    
            setWidth100();
            setHeight100();
    
            recreateBtn = new IButton("Recreate");
            recreateBtn.addClickHandler(new ClickHandler() {
                @Override
                public void onClick(ClickEvent event) {
                    new MyWindow().show();
                }
            });
            addMember(recreateBtn);
            new MyWindow().show();
            draw();
        }
    
        private class MyWindow extends Window {
            public MyWindow() {
                setWidth("95%");
                setHeight("95%");
                setMembersMargin(0);
                setModalMaskOpacity(70);
                setTitle(" (" + Version.getVersion() + "/" + Version.getSCVersionNumber() + ")");
                setTitle("ListGrid converts Set-Criteria to Or-Array of iContains-Criteria" + getTitle());
                setShowMinimizeButton(false);
                setIsModal(true);
                setShowModalMask(true);
                centerInPage();
    
                SelectItem si = new SelectItem("status", "Status");
                si.setMultiple(true);
                si.setValueMap(new LinkedHashMap<String, String>() {
                    {
                        put("Threatened", "Threatened");
                        put("Endangered", "Endangered");
                        put("Not Endangered", "Not Endangered");
                        put("Not currently listed", "Not currently listed");
                        put("May become threatened", "May become threatened");
                        put("Protected", "Protected");
                    }
                });
                final DynamicForm df = new DynamicForm();
                df.setFields(si);
                addItem(df);
    
                final IButton getFilter = new IButton("Show Filter", new ClickHandler() {
                    @Override
                    public void onClick(ClickEvent event) {
                        if (df.getValuesAsAdvancedCriteria() != null)
                            SC.say(df.getValuesAsAdvancedCriteria().toJSON());
                        else
                            SC.say("No filter");
                    }
                });
                getFilter.setWidth(200);
                addItem(getFilter);
    
                final IButton createListGrid = new IButton("Create ListGrid", new ClickHandler() {
                    @Override
                    public void onClick(ClickEvent event) {
                        if (lg != null && MyWindow.this.contains(lg)) {
                            MyWindow.this.removeItem(lg);
                            lg.markForDestroy();
                            lg = null;
                        }
                        lg = new AnimalsFilterTest(false);
                        addItem(lg);
                        lg.fetchData(df.getValuesAsAdvancedCriteria());
                    }
                });
                createListGrid.setWidth(200);
                addItem(createListGrid);
    
                final IButton getLGFilter = new IButton("Show ListGrid Filter", new ClickHandler() {
                    @Override
                    public void onClick(ClickEvent event) {
                        if (lg == null)
                            SC.say("No ListGrid");
                        else {
                            if (lg.getFilterEditorCriteria() != null)
                                SC.say(lg.getFilterEditorCriteria().asAdvancedCriteria().toJSON());
                            else
                                SC.say("No filter");
                        }
                    }
                });
                getLGFilter.setWidth(200);
                addItem(getLGFilter);
    
                final IButton refetchLG = new IButton("Re-fetch ListGrid", new ClickHandler() {
                    @Override
                    public void onClick(ClickEvent event) {
                        if (lg == null)
                            SC.say("No ListGrid");
                        else {
                            lg.setData((RecordList) null);
                            if (lg.getFilterEditorCriteria() != null)
                                lg.fetchData(lg.getFilterEditorCriteria().asAdvancedCriteria());
                            else
                                lg.fetchData();
                        }
                    }
                });
                refetchLG.setWidth(200);
                addItem(refetchLG);
    
            }
        }
    
        private class AnimalsFilterTest extends ListGrid {
            public AnimalsFilterTest(boolean setCriteria) {
                super(DataSource.get("animals"));
                setWidth(600);
                setHeight(200);
                setShowFilterEditor(true);
                setAutoFetchData(false);
                setAutoFitWidthApproach(AutoFitWidthApproach.BOTH);
    
                ListGridField lifeSpanLGF = new ListGridField("lifeSpan");
                ListGridField commonNameLGF = new ListGridField("commonName");
    
                ListGridField statusLGF = new ListGridField("status");
                SelectItem si = new SelectItem();
                si.setMultiple(true);
                if (setCriteria)
                    si.setOperator(OperatorId.IN_SET);
                statusLGF.setFilterEditorProperties(si);
    
                setFields(commonNameLGF, lifeSpanLGF, statusLGF);
                setSortField("commonName");
            }
        }
    }
    To see the issue do the following steps:
    1. Select Threatened and Endangered
    2. Click "Show filter" to see that inSet-criteria will be generated
    3. Click "Create ListGrid" to create the ListGrid with these criteria
    4. Click "Show ListGrid filter" to see that the ListGrid thinks it is using or-Array of iContains criteria (unexpected)
    5. Click "Re-fetch ListGrid" to see that with these criteria the resultset differs (expected, mistake in the step before)
    In my opinion the ListGridField should be using inSet criteria here if it successfully parses and accepts these criteria in Step 3 - or it should throw some kind of error message, but at least a warning.

    This is minor for me as I think I can fix the issue in my application with explicitly calling si.setOperator(OperatorId.IN_SET).

    Best regards
    Blama

  • #2
    Before you apply the IN_SET operator, the ListGrid is using simple Criteria, which when combined with textMatchStyle:"iContains", will result in the filtering you see. Switching the textMatchStyle to "equals" would result in the filtering you expect for that field, but that same textMatchStyle will apply to all other fields as well - that's all that simple Criteria can do.

    Once you specify the IN_SET operator, the grid switches over to AdvancedCriteria, and different fields can then use different operators.

    Comment

    Working...
    X