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

Date Only in In-line Edit with DateTime

6 Answers 2178 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Brendon
Top achievements
Rank 1
Brendon asked on 12 Dec 2012, 03:28 AM
I have a declared DateTime field in my model. In a Grid, while in "Edit" mode for a row, Kendo uses a DateTimePicker EditTemplate by default. I want the Date EditTemplate to be used as the time is ignored. How do I tell Kendo which Date picker to use?

Original Column:

columns.Bound(e => e.WeekStart).Format("{0:yyyy-MM-dd}");

Tried adding .Date to return only date, but in edit mode the Date + Time picker is still used:

columns.Bound(e => e.WeekStart.Date).Format("{0:yyyy-MM-dd}");

Thanks.

6 Answers, 1 is accepted

Sort by
0
Nikolay Rusev
Telerik team
answered on 12 Dec 2012, 09:03 AM
Hello Brendon,

Kendo Grid uses the standard ASP.NET MVC mechanism for generating editors, i.e EditorTemplates.
If you need to override the default ones you should create editor templates per your needs.

Here is more details on the matter:
http://blogs.msdn.com/b/nunos/archive/2010/02/08/quick-tips-about-asp-net-mvc-editor-templates.aspx
http://bradwilson.typepad.com/blog/2009/10/aspnet-mvc-2-templates-part-3-default-templates.html

Regards,
Nikolay Rusev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Brendon
Top achievements
Rank 1
answered on 12 Dec 2012, 05:08 PM
The template is already created. It is a default EditorTemplate called Date. The question is, why does Kendo Grid automatically select to use the DateTime template instead of the Date template. I need to force Kendo to use the proper template, but there appears to be no where to set this option in the Grid...
0
Nikolay Rusev
Telerik team
answered on 13 Dec 2012, 03:17 PM
Hello Brendon,

If the model has a field of type DateTime the default EditorTemplate is DateTime, if you need to change it you will have to modify the model property by adding the following attribute:
[DataType(DataType.Date)]
public DateTime LastSupply
{
 get;
 set;
}

The second blog post from my previous post explains how the editor templates is picked from the framework. Namely:
  • TemplateHint from ModelMetadata
  • DataTypeName from ModelMetadata
  • The name of the type (see notes below)
  • If the object is not complex: “String”
  • If the object is complex and an interface: “Object”
  • If the object is complex and not an interface: Recurse through the inheritance hiearchy for the type, trying every type name


  • Regards,
    Nikolay Rusev
    the Telerik team
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
    0
    Brendon
    Top achievements
    Rank 1
    answered on 13 Dec 2012, 04:01 PM
    I guess I was looking for a way to do this in the Grid itself, not from the model class. What if I did not have access to the model to add a DataType descriptor? In this case, the model is in the Business class model layer.

    That issue aside, using the example you gave does work.
    0
    Nikolay Rusev
    Telerik team
    answered on 13 Dec 2012, 04:28 PM
    Hello Brendon,

    You can change the editor per column by using EditorTemplateName. For example:
    columns.Bound(p => p.UnitPrice).Width(140).EditorTemplateName("Date")

    However this will apply only for InCell/InLine editing, but not for Popup editing. Hope that helps.

    All the best,
    Nikolay Rusev
    the Telerik team
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
    0
    Brendon
    Top achievements
    Rank 1
    answered on 13 Dec 2012, 04:38 PM
    Thank you. Exactly what I was looking for. It is only needed for inline/incell editing.
    Tags
    Grid
    Asked by
    Brendon
    Top achievements
    Rank 1
    Answers by
    Nikolay Rusev
    Telerik team
    Brendon
    Top achievements
    Rank 1
    Share this question
    or