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

[Solved] Default date when using incell editing in telerik grid

1 Answer 173 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.
Pablo
Top achievements
Rank 1
Pablo asked on 20 Feb 2012, 02:44 PM
Hi there,

I'm using a telerik mvc grid with incell editing mode. When adding a new row and clicking on one of the columns which is a date, the current date is being displayed by default, and i would like to avoid that. I just want to display an empty string in the datepicker until i select a date in the calendar.

My grid:
@(Html.Telerik().Grid(viewmodelList)
        .Name("AccountPayments")
        .DataKeys(keys =>
        {
            keys.Add(c => c.ID_Gen);
        })
                    .DataBinding(dataBinding =>
                dataBinding.Ajax()
                        .Select("SelectBankAccountPayments", "TaxForm", (ViewData["EngineParams"] as TaxFormEngineParameters).AddDialogType(Model.ID))
                        .Update("SaveBankAccountPayments", "TaxForm", (ViewData["EngineParams"] as TaxFormEngineParameters).AddDialogType(Model.ID))
            )
            .ToolBar(commands =>
            {
                commands.Insert();
                commands.SubmitChanges();
            })
        .Columns(columns =>
        {
            columns.Bound(p => p.ID_Gen).Hidden();
            columns.Bound(o => o.PaymentType).EditorTemplateName("PaymentType").Width(100);
            columns.Bound(p => p.Amount).Format("{0:c}").ClientTemplate("<#= formatAsCurrency(Amount) #> ");
            columns.Bound(p => p.Tax).Width(100).Format("{0:c}").ClientTemplate("<#= formatAsCurrency(Tax) #> ");
            columns.Bound(p => p.Gross).Format("{0:c}").ReadOnly(true).ClientTemplate("<#= formatAsCurrency(Gross) #> ");
            columns.Bound(p => p.PaymentDate).Format("{0:d}").Width(180);
            columns.Command(commands => commands.Delete()).Width(100).Title("Delete");
        })
                .ClientEvents(events => events
                .OnRowDataBound("ici_onRowDataBound")
                .OnEdit("ici_onEdit")
                .OnSubmitChanges("ici_onUpdate"))
        .Editable(editing => editing.Mode(GridEditMode.InCell))
        .Pageable()
        .Scrollable(scrollable => scrollable.Height(298))
        .Sortable()
        .Footer(false)
)


Any ideas?

Thanks in advance

1 Answer, 1 is accepted

Sort by
0
Petur Subev
Telerik team
answered on 21 Feb 2012, 12:26 PM
Hello Pablo,

I suppose this is because you are using the default DateTime editor template (under the Shared/EditorTempaltes folder) which has the following statement in it.

@model DateTime
 
@(Html.Telerik().DateTimePicker()
        .Name(ViewData.TemplateInfo.GetFullHtmlFieldName(string.Empty))
        .HtmlAttributes(new { id = ViewData.TemplateInfo.GetFullHtmlFieldName(string.Empty) + "_wrapper" })
        .Value(Model > DateTime.MinValue? Model : DateTime.Today)
)

You can change it to null if you change your model to nullable DateTime (i.e. DateTime?).

Regards,
Petur Subev
the Telerik team
Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
Tags
Grid
Asked by
Pablo
Top achievements
Rank 1
Answers by
Petur Subev
Telerik team
Share this question
or