Filter kendo datasource by month

306 Views Asked by At

I have a kendo datasource for which the data needs to be filtered by the selected month. Can a custom filter be applied to the datasource to achieve the same?

My datasource looks somewhat like this:

new kendo.data.DataSource({
                data: [{name:"Bill", dob:"01/02/1980"},
                        {name:"Bob", dob:"05/06/1981"},
                        {name:"Johnny", dob:"01/08/1980"},
                        {name:"James", dob:"09/10/1989"}]
            });

The dates are converted to string in the format mm/dd/yyyy

I need to apply a filter so as to retrieve the two records whose dob is on Jan 1980 here.

2

There are 2 best solutions below

0
On

You can try applying a complex filter as in this code:

filter: { logic: "and", filters: [ {field: "dob", operator: "contains", value: "01"}, {field: "dob", operator: "contains", value: "1980"} ] }

Here you can find a sample dojo page.

0
On

You could try the .filter() on the DataSource,

dataSource.filter( { field: "dob",  value: "01/02/1980" });
var filteredItems = dataSource.view();    
console.log(filteredItems); //This should return all the matched items