Filter wcf service by date?

6 posts, 0 answers
  1. Clint
    Clint avatar
    57 posts
    Member since:
    Feb 2011

    Posted 06 Sep 2012 Link to this post

    Trying to filter a WCF service by date.  I can filter via a grid/gui, and I can setup default filters for every other column/field.  I just can't seem to get the date to work. The error  I get back is........... "value":"Operator 'eq' incompatible with operand types 'Edm.DateTime' and 'Edm.String' Data format from the WCF is as follows... "EFFECTIVE_DATE":"\/Date(1065657600000)\/",

    One perplexing thing is that if I add the following, it filters by the top parameter, and the grid actually looks like it wants to filter by date.  If I click on the filter next to "EFFECTIVE DATE" is actually HAS the correct date and operator all filled in.  Clicking on "filter" then makes it filter perfectly.  So why won't it just filter it to begin with like every other type of field? 
    filter: [
    { field: "SYMBOL", operator: "eq", value: "NLP"},                   
    { field: "EFFECTIVE_DATE", operator: "eq", value:"\/Date(1065657600000)\/" }                       
    ],


    More to the example....
    <script>
        $(document).ready(function () {
            var grid = $("#grid").kendoGrid({
                dataSource: {
                    type: "odata",
                    transport: {
                        read: "http://someURL/Data.svc/Policies",
                        //  dataType: "json",                            
                    },
                    filter: [{
                        field: "SYMBOL",
                        operator: "eq",
                        value: "NLP"
                    }, {
                        field: "EFFECTIVE_DATE",
                        operator: "eq",
                        value: "\/Date(1065657600000)\/"
                    }],
                    schema: {
                        model: {
                            fields: {
     
                                SYMBOL: {
                                    type: "string"
                                },
                                FIRM_NAME: {
                                    type: "string"
                                },
                                EFFECTIVE_DATE: {
                                    type: "date"
                                },
                                PolicyStatusID: {
                                    type: "string"
                                },
                            }
                        }
                    },
                    pageSize: 20,
                    serverPaging: true,
                    serverFiltering: true,
                    serverSorting: true
                },
                height: 350,
                filterable: true,
                sortable: true,
                pageable: true,
                columns: [{
                    field: "FIRM_NAME",
                }, {
                    format: "{0:MM/dd/yyyy}",
                    field: "EFFECTIVE_DATE",
                    title: "EFFECTIVE_DATE",
                    //  template: '#= kendo.toString(EFFECTIVE_DATE, "MM/dd/yyyy") #'           
                }, {
                    field: "PolicyStatusID",
                }, {
                    field: "SYMBOL",
                }, ]
            });
     
        });
    </script>
  2. Daniel
    Admin
    Daniel avatar
    2230 posts

    Posted 12 Sep 2012 Link to this post

    Hello Clint,

    The format needed for the filter is different. You should just set a JavaScript Date and the DataSource will convert it in the needed format.

    Regards,
    Daniel
    the Telerik team
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
  3. Clint
    Clint avatar
    57 posts
    Member since:
    Feb 2011

    Posted 12 Sep 2012 Link to this post

    Had attempted to change format with js but just couldn't get it figured out.  Will give it another go.
  4. Daniel
    Admin
    Daniel avatar
    2230 posts

    Posted 17 Sep 2012 Link to this post

    Hi again Clint,

    It is not needed to apply the formatting with code. You just need to pass a JavaScript date and the DataSource will apply the format e.g.

    filter: [{
            field: "SYMBOL",
            operator: "eq",
            value: "NLP"
        }, {
            field: "EFFECTIVE_DATE",
            operator: "eq",
            value: new Date()
        }]
    I attached a small sample which demonstrates this functionality. 

    Regards,
    Daniel
    the Telerik team
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
  5. Clint
    Clint avatar
    57 posts
    Member since:
    Feb 2011

    Posted 27 Sep 2012 Link to this post

    Got the filtering working.... almost.  Now, the date is off.

    If I put...
    value: new Date(2011, 01, 11)

    And then look on the grid, it is filtering by February 11th, 2011.  The crazy thing is then the results of the grid are shown as being filtered on February 10, 2011.

    So the value I enter is January, 11, 2011
    the filter on the grid that is applied is February 10, 2011
    and the actual results are February 11, 2011.

    I've attached 2 screenshots
  6. Daniel
    Admin
    Daniel avatar
    2230 posts

    Posted 02 Oct 2012 Link to this post

    Hello Clint,

    The month is different because it is zero based. In order to initialize a new date with January as month, you should use the following constructor:

    new Date(2011, 0, 11)
    As for the day, this could occur if there is a difference in the timezone of the server and the client.  By default the browsers convert the dates to local time when initializing a new date object which will occur when creating a new date from the serialized JSON date. It is possible to use the schema parse function to convert the dates to UTC in order to avoid this behavior.

    Regards,
    Daniel
    the Telerik team
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Back to Top