简体   繁体   中英

Kendo Grid Inline edit kendo timepicker not changing value

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");

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', "");
        }
    })
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM