jQWidgets Forums
jQuery UI Widgets › Forums › Editors › DateTimeInput › using custom format date and time
Tagged: datetimeinput widget
This topic contains 23 replies, has 2 voices, and was last updated by qtipaddict 10 years, 6 months ago.
-
Author
-
But which callback function should I use in jqxDataAdapter? loadComplete doesn’t help me because I already format the Date objects when the data in the grid is fully loaded. It’s when the date is changed that it needs to be formatted again for display. And what do you mean “jqxDataAdapter or something else”? What else could I use besides jqxDataAdapter?
Hi qtipaddict,
Why should you use the dataAdapter’s loadComplete? You should use the dataAdapter’s formatDate to format a date. I still think that you do not understand how this works. A Grid Date Column always works with Javascript Date objects. You do not format your date, you specify the column’s cellsformat. This does not matter, the cell value is still JavaScript Date object. I strongly suggest you to read about JavaScript Date on the web.
Best Regards,
Peter StoevjQWidgets Team
http://www.jqwidgets.comI found a similar topic to the problem I am having, http://www.jqwidgets.com/community/topic/jqxgrid-date-formating
I believe these two jsFiddles will make things clearer.Example using “2014-11-06T00:00:00” and cellsformat works.
http://jsfiddle.net/r3d3Lc14/1/Example using “2014-11-06 00:00:00” (no ‘T’) and cellsformat has no effect.
http://jsfiddle.net/r3d3Lc14/2/In my application, I get the date from the Postgresql database which stores and returns timestamps in the format ‘yyyy-MM-dd HH:mm:ss’. I do not want to use the dataAdapter’s formatDate and hand-write the html for my grid as shown in your example.
Hello qtipaddict,
Ok, define your format in the source object as we have explained this in the Grid’s Data Sources help topic and it will work fine – Ex: http://jsfiddle.net/ze5crhdh/. Again, jqxGrid works only with JavaScript Date Objects. If you pass Strings to a Date column, the Grid will convert the String to a JavaScript Date.
Best Regards,
Peter StoevjQWidgets Team
http://www.jqwidgets.comThank you, Peter. I had to remove my custom cellsrenderer for the date to appear in the correct format. I learned that from your post in a different thread, http://www.jqwidgets.com/community/topic/problem-with-jqx-dataformat-formatdate-with-culture/. So now that I’m using the built-in rendering, I guess there’s no way for me to change the color of the text in that cell.
I noticed we don’t get the same results without the “.z” in
format: "yyyy-MM-dd HH:mm:ss.z"
. Unfortunately, this converts the date into local time. I need the formatted date to be in UTC.Hi qtipaddict,
Well, if you want it converted to UTC, you had to use the format with T. For changing cell color, you can use “cellclassname”.
Best Regards,
Peter StoevjQWidgets Team
http://www.jqwidgets.comDo you mean
format: "yyyy-MM-ddTHH:mm:ss"
? Or,var data = '[{"startDate":"2014-11-06T00:00:00.0"}]';
?I defined a style called “max” and then I added cellclassname to the grid like this:
{ text: 'date', datafield: 'startDate', cellsformat: 'ddHHmmZ MMM yyyy', cellclassname: 'max' }
but the colors did not change. What did I do wrong? http://jsfiddle.net/ze5crhdh/1/
Okay I’ve sort of narrowed it down. The milliseconds in
var data = '[{"startDate":"2014-11-06 00:00:00.0"}]';
is throwing offformat: "yyyy-MM-ddTHH:mm:ss"
. I tried ‘.S’ and ‘.f’ for the milliseconds but no joy. The Grid’s Data Sources help topic has an example of date formatting but it does not include the milliseconds. -
AuthorPosts
You must be logged in to reply to this topic.