This is a migrated thread and some comments may be shown as answers.

DateTime as Date only

2 Answers 126 Views
Grid
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Matthew
Top achievements
Rank 1
Matthew asked on 09 Jan 2012, 07:53 PM
I'm using a Grid with In-line editing.  I've got the display working properly, but when I go into edit mode the default editor is a Date and Time picker.  I just want a date picker (no time)

I changed the underlying SQL database to a "Date" column, but the ORM model doesn't seem to support a "Date" column so I'm stuck with a DateTime field.

How do I force a date picker (without time) in the grid?
c.Bound(j => j.DueDate).Width(105).Title("Due Date").Format("{0:d}").ClientTemplate("<#= $.telerik.formatString('{0:d}', DueDate) #>");
 
c.Bound(j => j.DueDate).Width(95).Title("Due Date").Format("{0:MM/dd/yyyy}");

2 Answers, 1 is accepted

Sort by
0
Petur Subev
Telerik team
answered on 11 Jan 2012, 09:01 AM
Hi Matthew,


Basically the DateTimePicker is used because it is the default component used as editor template for DateTime objects. You can either change the editor template called DateTime under the Shared/EditorTemplates folder to use DatePicker or you can use an [UIHint("YourEditorName")] attribute to specify a custom EditorTemplate which uses DatePicker.

Regards,
Petur Subev
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the Telerik Extensions for ASP.MET MVC, subscribe to their blog feed now
0
Matthew
Top achievements
Rank 1
answered on 11 Jan 2012, 02:09 PM
Perfect!  That worked.

I was a little nervous because my model is created via ORM.  I'll have to maintain the model manually from this point forward, but I don't see that as a big issue since my model is pretty stable at this point.

For those that don't know, I had to do the following:

1.  In my model add a reference to using System.ComponentModel.DataAnnotations;
2.  Add [UIHint("Date")] in my model for the DateTime field
3.  Modify my Date template to permit null dates by adding a question mark at the top of the template 

@model DateTime?

Note: I already had added question marks in the model for the DateTime field.

As always, thanks for your help.


Tags
Grid
Asked by
Matthew
Top achievements
Rank 1
Answers by
Petur Subev
Telerik team
Matthew
Top achievements
Rank 1
Share this question
or