Date automatically getting converted to MM/DD/YYYY after selection in datepicker

Tags: #<Tag:0x00007f0b02e2eb18>

I have used renderer to display date in my desired format

{data: “lastPaintDate”, type: ‘date’,renderer: ‘my.custom’, dateFormat: ‘DD/MM/YYYY’,correctFormat: true},

and it displayed correctly as below

But as soon as i am clicking the date cell to change the date through datepicker the date is being converted to full date with timestamp. See below:

And after that if I select a date from datepicker it gets converted to “MM/DD/YYYY” and sometimes “NaN/NaN/NaN” because date is taking the place of month. Have a look below:

Kindly look into this matter and suggest necessary solution.

Thanks

Hi @dasguptahirak

can you share a demo with your renderer?

@aleksandra_budnik Please find below jsFiddle url
https://jsfiddle.net/dasguptahirak/31z2eusL/7/

  1. First load it displays correctly (Have a look on first row date field being correctly rendered to “DD/MM/YYYY”)

  2. Clicking on date cell (It shows full timestamp onclick event)

  3. On selecting a date it gets converted to “MM/DD/YYYY”

As we have selected 16 Oct 2018 in above datepicker it gets converted to “10/16/2018” which is a invalid date for the datepicker in “DD/MM/YYYY” so it displays “Invalid date”.

Kindly have a look on this issue.

Sorry for keeping you waiting.

I did not get a notification on your post.

I will examine the code and share my thought tomorrow.

First, please let me know what is an intended behavior?

I see that you have a dateFormat in the columns settings but you also want to do something in the dRenderer renderer.

@aleksandra_budnik

Yes, we want to render the date in “DD/MM/YYYY” format when we are fetching it from database. And the rendering is working fine. But as soon as we want to change the date, then above issue is occurring. Is there any work around to resolve this issue?

Sorry for keeping you waiting @dasguptahirak

I did not find any workaround yet, but will update you if I find any.

@aleksandra_budnik is there any update on the above issue because i am also facing similar issue

Hey @vineeth

each implementation is different but you can try to call

instance.render();
instance.validateCells()

after you fetch new data.

Hi @aleksandra_budnik thanks for reply agree with you each implementation is different.
Fiddle Link: https://jsfiddle.net/vineetharkut/vk67qycm/15/
My scenario is I will be getting a CSV file in which I don’t know what data type format will be, so that why I first convert it to one format which is “YYYY-MM-DD” by using dateFormat option and as well as making one custom rendering variable to format the date but there is an issue when you see the format date at the output section month getting convert to date and vice versa. Even if you click on the third-row date, you can see that format has been changed to the old format and if you click outside the date picker then you will see date has been changed which is invalid.

Your title says that Date automatically getting converted to MM/DD/YYYY after selection in datepicker But I do not get the same effect. I get the format that you’ve used in the dateFormat (line 29).

What you would like to achieve after clicking on 19th of December 2018?

Hi, @aleksandra_budnik thanks for the reply.

if you see the date of the second row is “12/01/2018” (which is DD/MM/YYYY) but after formatting to YYYY-MM-DD it becomes “2018-12-01” the date become month and month become to date. I don’t know whether this is a momentJS fault. Similar issue with the third row also.

In third row of above screenshot which you share just have a look carefully when you clicking the drop-down icon to open the date picker the format was “YYYY-MM-DD” but when the date picker open and before clicking on any date in date picker the date format become “DD-MM-YYYY”, I don’t know why the format getting change but if click on any date in date picker then again the format will correct which is “YYYY-MM-DD”.

I can see what you mean @vineeth

Is your data column similar to the one is the demo? The algorytm becomes crazy as firstly two rows you want to change YYYY MM DD to YYYY MM DD (just different separators) but then you have YYYY DD MM and in the 4th row it’s YYYY MM DD again.