I have a grid with a date column. I use the rowEditDialog. When the dialog closes, I get the values and save them to the database.
I use ui.Value[].
Instead of getting a date. I get some strange string.
Here is the code.
{ columnKey: "MyDate", visible: true, readOnly: false, required: true, editorType: "datepicker", validation: false, editorOptions: { dateDisplayFormat: "date" }, }
The ui.Value["MyDate"] is
Mon Mar 14 2005 00:00:00 GMT-0500 (Eastern Standard Time) {}
That is the correct date but why is not coming back as '3/14/2005'
Just a follow up. If I change the dateType to string, I get the correct value when this is set to string.
Hello William Reyes,
Thank you for posting in our forum.
The text that the user sees in the grid cells gets formatted by a formatter utility function before being rendered. Using ui.value provides the Date object that the grid uses internally, not the cell text. In case you need the date in a MM/DD/YYYY format, calling the “getCellText” grid method for the currently edited cell would provide you the cell text. I am not sure which event you are handling, but I guess it is the editRowEnded (correct me if I am wrong?). Its “ui” parameter also gives you a reference to the rowID, which is needed when calling “getCellText”. The code might look like this:
Approach 1:
let cellText = $("#grid").igGrid("getCellText", ui.rowID, "MyDate");
Another possible approach is to construct the string yourself by calling the “getFullYear”, “getMonth” and “getDate” methods of the Date object. Then the code might look like this:
Approach 2:
let year = ui.values.MyDate.getFullYear() let month = ui.values.MyDate.getMonth() + 1 //this is because month index starts from 0 instead of 1 let day = ui.values.MyDate.getDate() let shortDate = month + "/" + day + "/" + year
You get “11122039” when you parse the date because this is the number of milliseconds that have passed since January 1, 1970 excluding the leap seconds – that is how JavaScript stores dates internally.
If you need any additional assistance, feel free to contact me.