Search code examples
asp.net-mvcteleriktelerik-gridtelerik-mvc

When grid enters edit mode DateTime picker clears value


I have a DateTime field bound to a grid. When the grid enters edit mode the date/time picker displays, but the value is cleared from it. This forces the user to re enter the date/time. Any idea why it value is cleared when the edit mode is triggered?

@(Html.Telerik().Grid<ExpenseGridModel>()
    .DataBinding(dataBinding => dataBinding.Ajax()
        .Select("ExpenseAjaxBinding", "ExpenseEntry")
        .Update("ExpenseUpdate", "ExpenseEntry")
    )
    .Name("ExpensesGrid")
    .DataKeys(keys => keys.Add(r => r.id))
    .Columns(columns =>
        {
            columns.ForeignKey(o => o.categoryId, Model.expenseCategories, "Id", "Name");
            columns.ForeignKey(o => o.typeId, Model.expenseTypes, "Id", "Name");
            columns.Bound(r => r.date);
            columns.ForeignKey(o => o.classId, Model.expenseClasses, "Id", "Name");
            columns.Bound(r => r.description);
            columns.Bound(r => r.amount);
            columns.Command(commands =>
                    commands.Edit()                                          
            );
        })
         )

Solution

  • I fixed the issue by setting the editor template. By default it was using the DateTime Picker. Fortunately I didn't need the TimePicker portion.

    columns.Bound(r => r.date).Format("{0:d}").EditorTemplateName("Date");