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:
To see the issue do the following steps:
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
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); [B] if (setCriteria) si.setOperator(OperatorId.IN_SET);[/B] statusLGF.setFilterEditorProperties(si); setFields(commonNameLGF, lifeSpanLGF, statusLGF); setSortField("commonName"); } } }
- Select Threatened and Endangered
- Click "Show filter" to see that inSet-criteria will be generated
- Click "Create ListGrid" to create the ListGrid with these criteria
- Click "Show ListGrid filter" to see that the ListGrid thinks it is using or-Array of iContains criteria (unexpected)
- Click "Re-fetch ListGrid" to see that with these criteria the resultset differs (expected, mistake in the step before)
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
Comment