How to add DatePicker in ClientTemplate for Kendo

2019-05-10 13:51发布

问题:

I am trying to port my code from syncfusion to telerik kendo MVC UI, I need to show Datepicker in Grid cell, and for which I have done in grid column as:

columns.Add("TemplateCol").Title("Out of date").TemplateColumn(true).TemplateName("TemplateOutOfDate");

and for TemplateOutOfDate I have made in seperate .cshtml file as

@Html.Syncfusion().DatePicker("OutOfDate" + Model.ID.ToString(), Model.OutOfDate).DefaultDate(Model.OutOfDate).DisplayDefaultDateOnLoad(true).DateFormat(Model.DefaultDateFormat).Width(75).OnSelect("onselect")

This .cshtml work fine in Syncfusion grid but when I port this code to Kendo().Grid it is not working So please tell me on we can achieve this using ClientTemplate to add DatePicker in Kendo Grid.

Thanks,Ajit

回答1:

Try this

columns.Bound(c => c.BirthDate).HtmlAttributes(new
    {
        @class = "templateCell"

    }).ClientTemplate(
     Html.Kendo().DatePicker()
      .Name("FDPicker_#=ID#")
      .Format("{0:dd/MM/yyyy}")
      .HtmlAttributes(new { data_bind = "value:BirthDate" })
      .ToClientTemplate().ToString()
      ).Format("{0:dd/MM/yyyy}");

More Details