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

  • ListGrid, AdvanceCriterions and date range filtering

    I can't seem to get date range filtering to work.
    This is what I've tried separately, so far:

    		AdvancedCriteria filterAC = new AdvancedCriteria(JSON.decode(
    				"{" +
    				"	_constructor:\"AdvancedCriteria\"," +
    				"	operator:\"and\"," +
    				"	criteria:" +
    				"	[{" +
    //				"		fieldType:\"date\"," +
    				"		fieldName:\"DATE_TIME\"," +
    				"   	operator:\"betweenInclusive\"," +
    				"   	start:\"Date(99,0,0,0,0,0)\"," +
    				"   	end:\"Date()\"" +
    				"	}]" +
    I'm using SmartGWT 2.0, and I know new constructors were added in AdvanceCriterions, but doing things this way should be okay, right?

    		DateItem gpsTimeFromItem = new DateItem("DATE_TIME", "From");
    		gpsTimeFromItem.setDefaultValue(new Date(110, 3, 10));
    //		gpsTimeFromItem.setCriteriaField("DATE_TIME");
    I also tried creating two DateItems, one "From" and one "To", linked it to the same field via "setCriteriaField" and that didn't work either.

    Can someone please point me to an working example of client-side date range filtering?
    I've seen the (and applied) the date range filtering in the SmartClient Explorer, but to no avail.

  • #2
    The creation of the criteria looks fine. You didn't say what actual problem you're having, so no further advice can really be given.


    • #3
      I have a populated ListGrid (through a DataSource) that has a field named DATE_TIME.
      That field contains the date and time that comes from the server in JSON as:
      "DATE_TIME": "\/Date(1266926160000+0100)\/"
      So, now I want to put a DynamicForm with two DateItems (one that will specify the "From" date and one the "To" date) beside that ListGrid. I then want to show only the records that are between those two dates.

      The dates don't have to be specified through the form. They can just be hardcoded (that's why I've tried doing it through AdvancedCriteria).

      The problem is that it doesn't work. As in, when call the ListGrid.filterData method, ALL the records get filtered out.
      I got some success, when I was really specific (operator:Equals and iContains) and searching for "Tue Feb 23 2010 12:56:00 GMT+0100 (Central Europe Standard Time)"


      • #4
        My Problem is same ... i can't filter Date's .


        • #5
          See the Date and Time Format and Storage overview for general information about working with dates.

          If you are having trouble using dates in criteria, post a sample of what you are doing, ideally runnable code.

          Also see the FAQ for the many other items that are required when posting (version, browser(s), etc).


          • #6
            I am doing as below but its not filtering the results as expected so please do needful.

            And also sorting doesn't works in case of Dates.

            AdvancedCriteria moreFilterCriteria = new AdvancedCriteria();
            boolean noCriteria = true;

            final DateTimeFormat dateFormat = DateTimeFormat.getFormat(MYAssaAbloyConstants.MM_DD_YYYY);
            final Date statementFromDate = form.getValuesAsCriteria()
            if (null != statementFromDate) {
            moreFilterCriteria.addCriteria(new AdvancedCriteria(new Criterion(MYAssaAbloyConstants.STATEMENT_DATE_FIELD,
            OperatorId.GREATER_OR_EQUAL, dateFormat.format(statementFromDate))));
            noCriteria = false;

            final Date statementToDate = form.getValuesAsCriteria()
            if (null != statementToDate) {
            moreFilterCriteria.addCriteria(new AdvancedCriteria(new Criterion(MYAssaAbloyConstants.STATEMENT_DATE_FIELD,
            OperatorId.LESS_OR_EQUAL, dateFormat.format(statementToDate))));
            noCriteria = false;


            • #7
              If you want to filter on date values, provide Date instances, not Strings.
              Last edited by Isomorphic; 19th Apr 2017, 23:32.


              • #8
                Thanks for your prompt response Admin....My issues is resolved now... .sorting and filtering works fine.