This is a migrated thread and some comments may be shown as answers.

Filter wcf service by date?

5 Answers 131 Views
Data Source
This is a migrated thread and some comments may be shown as answers.
Clint
Top achievements
Rank 1
Clint asked on 07 Sep 2012, 04:48 AM
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>

5 Answers, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 12 Sep 2012, 07:27 AM
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!
0
Clint
Top achievements
Rank 1
answered on 12 Sep 2012, 10:57 AM
Had attempted to change format with js but just couldn't get it figured out.  Will give it another go.
0
Daniel
Telerik team
answered on 17 Sep 2012, 07:09 AM
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!
0
Clint
Top achievements
Rank 1
answered on 27 Sep 2012, 05:04 AM
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
0
Daniel
Telerik team
answered on 02 Oct 2012, 08:26 AM
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!
Tags
Data Source
Asked by
Clint
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Clint
Top achievements
Rank 1
Share this question
or