Kendo Grid Inline edit kendo timepicker not changing value

混江龙づ霸主 提交于 2020-03-25 17:49:18

问题


Hi I have grid with inline editing when i want to click cell to update i can see my timepicker and i can select value but when i pass next cell value is disappearing and not select or changing anything

How can i solve it?

    @( Html.Kendo().Grid<MockUpForeNet.Controllers.CardDetailController.Days>()
        .Name("timegrid")
         .DataSource(d => d.Ajax().Read("TimeGridBinding", "CardDetail", new { rule = rule }).Update("UpdateTime","CardDetail").Model(keys =>
    {
       keys.Id(k => k.DayId);
       keys.Field(c => c.DayName).Editable(false);
       keys.Field(c => c.DayId).Editable(false);
       keys.Field("TimeStart", typeof(string)).Editable(true);
       keys.Field("TimeEnd", typeof(string)).Editable(true);
    }).PageSize(7))
               .Columns(c =>
                {
                    c.Bound(p => p.DayId).Width(100).Title(" ").ClientTemplate("#= chk2(data) #").Sortable(false);
                    c.Bound(e => e.DayName).Width(200).Title("Day");
                    c.Bound(e => e.TimeStart).Width(200).Title("Start Time").EditorTemplateName("StartTimeEditor");
                    c.Bound(e => e.TimeEnd).Width(200).Title("End Time").EditorTemplateName("EndTimeEditor");
                })
               .ToolBar(commands =>
                {
                    commands.Save().SaveText(" ").CancelText(" ");
                })
       .Editable(editing => editing.Mode(Kendo.Mvc.UI.GridEditMode.InCell))
       .Sortable()
       .ColumnMenu()
    )

Here my example editor

@(Html.Kendo().TimePicker().Name("txtend").Format("HH:mm").Value("23:59").Interval(30))

Here my model

    public class Days
    {
        public int DayId { get; set; }

        public string DayName { get; set; }

        [DataType(DataType.Time)]
        public DateTime TimeStart { get; set; }
        public DateTime TimeEnd { get; set; }
    }

Here example of how to bind data

                    Days d = new Days();
                    d.DayId = 1;
                    d.DayName = "Monday";
                    d.TimeStart = Convert.ToDateTime("00:00");
                    d.TimeEnd = Convert.ToDateTime("23:59");

回答1:


Add Colum with editor template as

columns.Bound(c => c.TimeStart).Title("Trainer").EditorTemplateName("StartTimeEditor").Width(250);

Editor template you can change as follows

@using System.Collections

@(Html.Kendo().DateTimePicker()
.Name("TimeStart")
.TimeFormat("hh:mm")
    .HtmlAttributes(new { style = "width:100%",data_format = "hh:mm" })
        .Events(e =>
         {
             e.Change("DtChange");
         })
)

Write a change function Dtchange() as follows with selected rowID

    function Dtchange() {
    var dataSource = $("#Grid").data("kendoGrid").dataSource;
    var data = dataSource.data();
    $.each(data, function (index, rowItem) {
        var date = data[index].TimeStart;
        var newdate = moment(date).format('hh:mm');
        if (newdate != 'Invalid date') {
            data[index].set('TimeStart', newdate );
        }
        else {
            data[index].set('TimeStart', "");
        }
    })
}


来源:https://stackoverflow.com/questions/60426643/kendo-grid-inline-edit-kendo-timepicker-not-changing-value

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!