2

I have a KendoGrid with a filterable European format date column with date operators for eq, gt, lt, gte, lte and I am trying to set it dynamically from JavaScript

columns:

{ field: "myDate", sortable: true, filterable: { ui: function(element) { element.kendoDatePicker({ format: "dd/MM/yyyy" }); } }, title: "my dte", width: "150px", minResizableWidth: "25", format: "{0:dd/MM/yyyy}" }

when I am trying to set the filter date dynamically like this:

filter.filters[0].value = '12/05/2019' 

the dates are getting reversed to 05/12/2019 and if I try with dates where the first part which is supposed to be the day is bigger than 12 (ex: 13/12/2019), the filters are showing up empty. The thing is that even if I reverse the date that I am passing with something like:

e=d.substr(0,5).split("/").reverse().join("/")+d.substr(5)

the filters WILL be shown in the filters fields, but they are not working.

DEMO link with instruction to reproduce: https://dojo.telerik.com/OGUgiGex

wilbi
  • 225
  • 2
  • 14

1 Answers1

1

In your link, when the filter change you set the value of filters with a string like this :
"value":"10/15/2016" and "value":"12/19/2022"

You should use a Date like this :
"value":new Date("2019-10-15") and "value":new Date("2022-12-19")

You can use another way to construct the Date, the main point is to use Date instead of string in your filter setting.

Azepic
  • 66
  • 1
  • 2
  • 5
  • Thanks for your answer, but in fact in my code I am saving to the database the filters that I am getting from the dataSource.filter() as they are. And for some reason the dates with the months are keep getting swapped. If you got any tip of what I could check for this issue, please comment – wilbi Nov 20 '19 at 07:14
  • 1
    @WilliamBird maybe you should look in the way you save the content of dataSource.filter(). If you change the content of the "Change filter dates" button onclick event with this `console.log(dataSource.filter());` then run, change the date filter via UI and click on the button. Then the "value" in the console is a Date Object too. So maybe when you save it, the "value" is tranformed to string and maybe that is the issue. – Azepic Nov 26 '19 at 15:35
  • thanks @Azepic but I still got that strange problem which I am not able to reproduce in DOJO and to debug in chrome. It's really strange, the first time that I click on the date filters if the dates are less than 12 the are getting reversed and if they are above 12 as Kendo assume they are invalid it's clearing the field. For example when I try filters: 02/04/2019 when I click filter and go again to check the value, it's reversed to 04/02/2019 if I click again filter, it's reversing again to 02/04/2019 etc – wilbi Nov 28 '19 at 13:49