Announcement

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

    ListGrid filtering locally with DateTime equals Today does not work.

    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:
    Code:
    { "_constructor":"AdvancedCriteria", "operator":"and", "criteria":[ { "fieldName":"Date Time Field", "operator":"betweenInclusive", "start":new Date(1460088000000), "end":new Date(1460174399999) } ] }
    between:
    Code:
    { "_constructor":"AdvancedCriteria", "operator":"and", "criteria":[ { "operator":"betweenInclusive", "fieldName":"Date Time Field", "start":new Date(1460088000000), "end":new Date(1460174399999) } ] }
    Interestingly, if you click the "Reload" button, the "equals" to "Today" will work as it causes fetches (you can see the "Loading..." flash).

    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);
        }
    }
    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)
    Attached Files
    Last edited by stonebranch1; 11 Apr 2016, 08:17.

    #2
    You can also reproduce this with a small modification the showcase "grid_daterange_presets"

    http://www.smartclient.com/smartgwt/...erange_presets

    If you change the type from a Date to a DateTime in PresetDateRangeXmlDS.java
    Code:
            DataSourceDateTimeField orderDateField = new DataSourceDateTimeField("orderDate", "Order Date");
    Then add another record for Today that is not midnight (aka "00:00" time) in PresetDateRangeData.java
    Code:
                    createRecord("C000001", "Bobs Tools Inc", "1200000", new Date(), "foo bar", 42),
    When you click "Filter" for equals Today, you will see the entry above "foo bar" will be hidden (that is, not qualify for the filter).
    Attached Files

    Comment


      #3
      Hi Isomorphic,

      I realize this one is still within the 3 business day window, however, wondering if you have any interim information to share with respect to this issue as we need to prepare some feedback.

      Thank you kindly

      Comment


        #4
        We can reproduce it and we've almost narrowed down the cause. It should be fixed later this week.

        Comment


          #5
          Thank you for the update.

          Comment


            #6
            We've made a fix for this problem for SGWT 4.1p/SC 9.1p and newer which will be in the nightly builds dated 2016-04-15 and beyond.

            One note, while not directly causing a problem in this situation, the field identifiers from your sample code:
            Code:
            public static final String f1 = "String Field";
            public static final String f2 = "Integer Field";
            public static final String f3 = "Date Time Field";
            aren't valid. Spaces aren't allowed. For further information, see http://www.smartclient.com/smartgwt-...a.lang.String-.

            Comment


              #7
              I downloaded the 15th build and it works however I now see this log message in the developer console when I filter on equals "Today":


              12:49:49.001:MUP6:WARN: DataSource:myDatasource:Operator betweenInclusive is not valid for field myDateTimeField. Continuing anyway.


              Should I be concerned about this?
              Last edited by stonebranch1; 15 Apr 2016, 09:01.

              Comment


                #8
                Ah I see why we are getting that warning. We are only allowing IBETWEEN_INCLUSIVE on DateTime fields so that the text of the operator says "between (inclusive)", rather than "between (inclusive match case)".

                Comment


                  #9
                  We do have eventual plans to allow a distinct title for operators when used on non-text fields, so they don't say "match case" in that case.

                  Aside from that, do you have any remaining issues in this thread?

                  Comment


                    #10
                    Nope, all good thank you.

                    Comment

                    Working...
                    X