When a ListGrid is filtering locally (not fetching data) and I specific a DateTime field as "equals" to "Today", no data is shown (nothing matches) even though there are dates that do qualify. If applying the filter causes a fetch to be performed, then the correct results are displayed. Also if after choosing "equals" to "Today", I change the operator to "Between", it automatically defaults the start and end to what the Today should also resolve to, but in this case the filter actually does wok.
Below is code to reproduce the problem. Run it and then select "Date Time Field" in the filter and pick "equals" as the operator. The value will default to Today. Then click the filter button and you will see no data appears to match. Then change the operator to "between" and click filter again. Data is shown as expected. The JSON filter for both cases looks identical:
Equals:
between:
Interestingly, if you click the "Reload" button, the "equals" to "Today" will work as it causes fetches (you can see the "Loading..." flash).
Tried both: SmartClient Version: v10.1p_2016-01-03/Pro Deployment (built 2016-01-03) & SmartClient Version: v10.1p_2016-04-08/Pro Deployment (built 2016-04-08)
Below is code to reproduce the problem. Run it and then select "Date Time Field" in the filter and pick "equals" as the operator. The value will default to Today. Then click the filter button and you will see no data appears to match. Then change the operator to "between" and click filter again. Data is shown as expected. The JSON filter for both cases looks identical:
Equals:
Code:
{ "_constructor":"AdvancedCriteria", "operator":"and", "criteria":[ { "fieldName":"Date Time Field", "operator":"betweenInclusive", "start":new Date(1460088000000), "end":new Date(1460174399999) } ] }
Code:
{ "_constructor":"AdvancedCriteria", "operator":"and", "criteria":[ { "operator":"betweenInclusive", "fieldName":"Date Time Field", "start":new Date(1460088000000), "end":new Date(1460174399999) } ] }
Code:
public class TestToday implements EntryPoint { public static final long MILLISECONDS_IN_A_SECOND = 1000; public static final long MILLISECONDS_IN_A_MINUTE = MILLISECONDS_IN_A_SECOND * 60L; public static final long MILLISECONDS_IN_A_HOUR = MILLISECONDS_IN_A_MINUTE * 60L; public static final long MILLISECONDS_IN_A_DAY = MILLISECONDS_IN_A_HOUR * 24L; DataSource dataSource; ListGrid grid; int counter = 0; ListGridRecord[] cacheData = new ListGridRecord[8]; public static final String fpk = "ID"; public static final String f1 = "String Field"; public static final String f2 = "Integer Field"; public static final String f3 = "Date Time Field"; private void loadData(int size) { cacheData = new ListGridRecord[size]; long now = System.currentTimeMillis(); long threeDaysInPast = now - ((size / 4) * MILLISECONDS_IN_A_DAY); Date d = new Date(threeDaysInPast); for (int i = 0; i < cacheData.length; i++) { cacheData[i] = new ListGridRecord(); cacheData[i].setAttribute(fpk, i); cacheData[i].setAttribute(f1, "abc-" + i); cacheData[i].setAttribute(f2, i * 10); cacheData[i].setAttribute(f3, d); d = new Date(d.getTime() + (10 * MILLISECONDS_IN_A_HOUR)); } } @Override public void onModuleLoad() { final VLayout appLayout = new VLayout(); appLayout.setWidth100(); appLayout.setHeight100(); loadData(24); buildDataSource(); buildGrid(); final FilterBuilder fb = new FilterBuilder(); fb.setTopOperatorAppearance(TopOperatorAppearance.RADIO); fb.setTopOperator(LogicalOperator.AND); fb.setShowModeSwitcher(Boolean.FALSE); fb.setDataSource(dataSource); IButton filterButton = new IButton("Filter"); filterButton.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { AdvancedCriteria criteria = fb.getCriteria(); Criteria resolvedCriteria = dataSource.convertRelativeDates(criteria); JSONEncoder encoder = new JSONEncoder(); encoder.setDateFormat(JSONDateFormat.LOGICAL_DATE_CONSTRUCTOR); String textCriteria = encoder.encode(resolvedCriteria.getJsObj()); SC.say(textCriteria); grid.filterData(criteria); } }); IButton reloadButton = new IButton("Reload"); reloadButton.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { grid.invalidateCache(); } }); appLayout.setMargin(5); appLayout.setMembersMargin(5); appLayout.addMembers(fb, filterButton, reloadButton, grid); appLayout.draw(); } private void buildGrid() { grid = new ListGrid(); grid.setDataFetchMode(FetchMode.PAGED); grid.setTitle("Test Grid"); grid.setAutoFetchData(true); grid.setAutoFitFieldsFillViewport(Boolean.TRUE); grid.setAutoFitWidthApproach(AutoFitWidthApproach.BOTH); grid.setAutoFitFieldWidths(Boolean.TRUE); grid.setCanFreezeFields(Boolean.FALSE); grid.setCanGroupBy(Boolean.FALSE); grid.setRecordComponentPoolingMode(RecordComponentPoolingMode.RECYCLE); grid.setAlternateRecordStyles(Boolean.TRUE); grid.setHeight100(); grid.setWidth100(); ListGridField gfld1 = new ListGridField(f1, "Field 1"); ListGridField gfld2 = new ListGridField(f2, "Field 2"); ListGridField gfld3 = new ListGridField(f3, "Field 3"); grid.setFields(gfld3, gfld1, gfld2); grid.setDataSource(dataSource, grid.getAllFields()); } private void buildDataSource() { dataSource = new DataSource(); dataSource.setClientOnly(true); DataSourceField fldId = new DataSourceField(fpk, FieldType.INTEGER); fldId.setPrimaryKey(true); DataSourceField fld1 = new DataSourceField(f1, FieldType.TEXT); DataSourceField fld2 = new DataSourceField(f2, FieldType.INTEGER); DataSourceField fld3 = new DataSourceField(f3, FieldType.DATETIME); dataSource.setFields(fldId, fld1, fld2, fld3); dataSource.setCacheData(cacheData); } }
Comment