Announcement

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

    filter criteria for date field getting changed to current date

    Hi, looks like there is some problem with applying a greaterThan filter criteria to a ListGrid when applying to a date field. I've observed this problem in both Smartclient 9.1 and Smartclient 10.0.

    See this example:
    http://www.smartclient.com/docs/9.1/a/system/reference/SmartClient_Explorer.html#filterBuilderBracketFS

    Use this code. You will see the independence date filter is set to the current date and not 1901-05-12?

    Code:
    isc.FilterBuilder.create({
        ID:"advancedFilter",
        dataSource:"worldDS",
        criteria: { _constructor: "AdvancedCriteria",
            operator: "and", criteria: [
                {fieldName: "independence", operator: "greaterThan", value: "1901-05-12"}
            ]
        }
    });
    
    isc.ListGrid.create({
        ID: "countryList",
        width:550, height:224, alternateRecordStyles:true, 
        dataSource: worldDS,
        fields:[
            {name:"countryName"},
            {name:"continent"},
            {name:"population"},
            {name:"area"},
            {name:"gdp"},
            {name:"independence"}
        ]})
    
    isc.IButton.create({
        ID:"filterButton",
        title:"Filter",
        click : function () {
            countryList.filterData(advancedFilter.getCriteria());
        }
    })
    
    isc.VStack.create({
        membersMargin:10,
        members:[ advancedFilter, filterButton, countryList ]
    })
    
    // Perform the initial filter
    filterButton.click();

    #2
    Do you have your inputFormat set to YMD? If not, then this is expected behavior.

    Either pass a date-string in the correct format, presumably MDY, or pass a date instance instead of a string.

    Comment


      #3
      After further inspection, this dateFormat is getting applied when we save the criteria string to our database. When I select a date and inspect it in the browser, it is properly displaying as a Date. However, when I save the string to the database, I see it formatted as yyyy-mm-dd in the dev console DSRequest before it is sent to the server. I've removed any date customizations that I thought might be interfering and tried to find a suitable sample in your Feature Explorer to recreate but not sure what to use. Any ideas why the date is being converted to that format in the DSRequest?

      Comment


        #4
        We're not sure on your serialization technique, but have you seen the doc for JSON.encode()? That might clear things up.

        Comment


          #5
          Also, the Date Format & Storage overview at #group..dateFormatAndStorage and the doc for JSONEncoder.dateformat may be useful reading.

          Comment


            #6
            Thank you, changing the dateFormat fixed it. I noticed a lot of recurring questions in the logs about this after you mentioned encoding. Perhaps some warning in the dev console might help? Also, why did I have to set dateFormat on isc.JSONEncoder but call isc.JSON.encode()? It took me a few minutes to figure that out and the docs seems to suggest that isc.JSONEncoder.encode() is a valid method but wouldn't work for me.

            Comment


              #7
              Can you show a sample? Or clarify what you mean by it wouldn't work for you.

              Comment


                #8
                I mean that my fix looked like this:

                isc.JSONEncoder.addProperties({dateFormat:"dateConstructor"});

                var encodedFilterCriteria = isc.JSON.encode(fundAssetsGrid.filterCriteriaAT);

                Why doesn't isc.JSONEncoder.encoder() work as the docs suggest?
                http://www.smartclient.com/docs/9.1/a/b/c/go.html#method..JSONEncoder.encode

                Comment


                  #9
                  Because encode() is not a static method on JSONEncoder - but something like this should work:

                  Code:
                  isc.JSONEncoder.create(settings).encode(object);

                  Comment

                  Working...
                  X