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

Kendo is before or equal to date not filtering

1 Answer 379 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Dan
Top achievements
Rank 1
Dan asked on 27 Dec 2016, 10:01 PM

I am using the javascript kendo grid and applying a custom filter for the year of 2015.  This is my code

 

//Filter by Year
        $('#year').on('change', function() {
            var grid = $("#grid").data("kendoGrid");
            var val = this.value;
            var fd = new Date(val, 0, 1);
            var firstday = fd;
            var ld = new Date(val, 11, 31);
            var lastday = ld;
            grid.dataSource.filter({
                logic: "and",
                filters: [
                    { field: "CheckDate", operator: "gte", value: firstday },
                    { field: "CheckDate", operator: "lte", value: lastday }
                ]
            });
        });

 

The last date of the year is set as filter 12/31/2015. However, when the filter is applied it doesn't return any of the items with the 12/31/2015.  It returns everything else but anything with the last date of the year.

1 Answer, 1 is accepted

Sort by
1
Dimiter Topalov
Telerik team
answered on 28 Dec 2016, 09:13 AM
Hello Dan,

The new Date(2015, 11, 31) method will return a date object with the time set to 00:00:00 local time (based on the browser location, e.g. "Thu Dec 31 2015 00:00:00 GMT+0200 (FLE Standard Time)". If the Grid data contain dates with other times (later than 0:00), the respective data items will be filtered out by such filter. You can avoid this by passing time to the new Date() method as well, e.g.:

var ld = new Date(2015, 11, 31, 23, 59, 59);

I have prepared a simple example, illustrating the described approach:

http://dojo.telerik.com/umUpu

I hope this helps, but if I am missing something, or the issue persists, please send us a similar isolated runnable project (you can use the Kendo UI Dojo), or modify the one above until the undesired behavior can be observed, so we can inspect it further, and determine what might be causing it. Thank you in advance.

Regards,
Dimiter Topalov
Telerik by Progress
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
Grid
Asked by
Dan
Top achievements
Rank 1
Answers by
Dimiter Topalov
Telerik team
Share this question
or