Datagrid date format

Archived from the Xataface Users forum.

njw — Sun Apr 29, 2012 6:57 am

I can’t see this question answered elsewhere, but apologies if it is.

I have a database with a date field. This formats correctly in view, edit and list views, e.g. “2012-04-06”. However in DataGrid view, it shows as “Fri Apr 6, 2012 00:00:00 (and more)”. How can I change the format to just show the date please?

Many thanks for any help.


shannah — Mon May 07, 2012 11:26 am

I have fixed this in SVN. rev. 3561
http://weblite.ca/svn/dataface/modules/DataGrid/trunk

Diff:

Code: Select all
van-fcat-07:DataGrid shannah$ svn diff -r 3560:3561 Index: js/DataGrid.js =================================================================== --- js/DataGrid.js   (revision 3560) +++ js/DataGrid.js   (revision 3561) @@ -42,16 +42,24 @@    if ( fielddef.vocabulary ){       out.renderer = Dataface.renderers[fielddef.vocabulary];    } -    -   if ( fielddef.Type.match(/^time/) ){ +   var dFormat = null; +   if ( fielddef.Type.match(/datetime|timestamp/) ){ +      dFormat = 'Y-m-d H:i:s'; +   } else if (fielddef.Type.match(/date/) ){ +       +       +      dFormat = 'Y-m-d'; +   } else if ( fielddef.Type.match(/^time/) ){       //alert('time field'); -      var format = 'H:i'; -      if ( fielddef.widget.format ){ -         format = fielddef.widget.format; +      dFormat = 'H:i'; +   } +   if ( dFormat != null ){ +      if ( typeof(fielddef['DataGrid.format']) != 'undefined' && fielddef['DataGrid.format'] ){ +         dFormat = fielddef['DataGrid.format'];       }       out.renderer = function(v){          if ( v instanceof Date ){ -            return v.format(format); +            return v.format(dFormat);          } else {             return v;          } @@ -89,6 +97,7 @@       case 'text':                 if ( fielddef.Type.match(/date|timestamp/) ){ +                         return new Ext.form.DateField(options);          } else if ( fielddef.Type.match(/time/) ){             //alert("Time field: "+options.interval); @@ -159,6 +168,8 @@    if ( fielddef.Type.match(/datetime|timestamp/) ){       options.format = 'Y-m-d H:i:s';    } else if (fielddef.Type.match(/date/) ){ +       +             options.format = 'Y-m-d';    } else if ( fielddef.Type.match(/time/) ){     @@ -174,7 +185,6 @@       }              options.renderer = function(v){ -         alert(v);          if ( v instanceof Date ){             return v.format(options.format);          } else {

-Steve


njw — Mon May 07, 2012 12:42 pm

Many thanks Steve. What’s the chance of being able to allow different date formats. Being a Brit, I prefer dd-mmm-yy? I can work with YYYY-MM-DD for now if it’s not a quick fix - or if you point me to what needs to change.

Thanks again

Neil


shannah — Mon May 07, 2012 1:02 pm

You can specify the format in the fields.ini file using the DataGrid.format directive.

e.g.

Code: Select all
[myfield] DataGrid.format="d/m/Y"

-Steve


njw — Tue May 08, 2012 1:46 am

That’s great.

Many thanks

Neil