Kendo DataSource.filter(date) causes application to crash

248 Views Asked by At

I'm trying to filter some data for a chart with date-sensitive information

if I select a date range, with no date, that would return an empty array of results, the application doesn't crash, but as soon as there is data withing the range of the FilterDate and gte (hence, there are points made after the filterDate), then the application crashes on that line.

axisChange : function(){
  //set date from period
  var filterDate = new Date();

  switch(this.get('selectedPeriod'))
  {
    case 'week':
      filterDate.setMonth(filterDate.getMonth()-1);
      break;
    case 'day':
      filterDate.setDate(filterDate.getDate()-7);
      break;
    case 'hour':
      filterDate.setDate(filterDate.getDate()-1);
      break;
  }
  /*var chart = jQuery("#chart").data("kendoChart");
  chart.setOptions({ categoryAxis: { baseUnit: this.get('selectedCategory') }});*/
  dataSource.filter({
    "field": "CreatedAt",
    "operator": "gt",
    "value": filterDate
  });
}

EDIT

ON closer inspection this is an issue with dataSource.filter, specific to the date, if I try to use another filter like:

dataSource.filter({
                        "field": "Note",
                        "operator": "contains",
                        "value": 'e'
                    });

everything is updated okay according to the filter.

FOR DETAILED CODE, PLEASE VISIT GITHUB REPO

https://github.com/Danelund/NeuroHelper/blob/master/NeuroHelper/scripts/app.js

2

There are 2 best solutions below

1
On

My first thought about this problem is about date format. Place a breakpoint before dataSource.filter line and check what is the date format. Probably you should also convert this date object to string using some kind of date.toString() function.

dataSource.filter({
  "field": "CreatedAt",
  "operator": "gt",
  "value": filterDate.toString()
});
0
On

Have you specified the type of the field that you want to filter (i.e. CreatedAt) to be of type "date" ? How to do so is demonstrated here.

schema: {
model: {
  id: "ProductID",
  fields: {
    CreatedAt: {
      type: "date"
    },