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

Kendo Grid Inline edit kendo timepicker not changing value

2 Answers 699 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Adil
Top achievements
Rank 1
Iron
Iron
Veteran
Adil asked on 04 Mar 2020, 01:13 PM

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()
    )     

2 Answers, 1 is accepted

Sort by
0
Adil
Top achievements
Rank 1
Iron
Iron
Veteran
answered on 04 Mar 2020, 01:14 PM

Sorry I Posted some missing data

Here my Template 

@(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");
0
Nikolay
Telerik team
answered on 06 Mar 2020, 10:04 AM

Hello Adil,

Thank you for sharing the Grid declaration.

I have examined the code and may have found what is causing this issue. The DatePicker name is set to "txtend" but the grid does not have a column with such a field, the field name seems to be "TimeStart". When such a mismatch occurs the binding will fail to work thus the value from the picker will not be sent to the controller. 

As a possible resolution I would suggest using a DatePickerFor as shown below:

@model DateTime

@Html.Kendo().DatePickerFor(m => m)

For your convenience, I am attaching a small MVC Grid demo demonstrating the above. Let me know if you have any questions.

Regards,
Nikolay
Progress Telerik

Get quickly onboarded and successful with your Telerik UI for ASP.NET MVC with the dedicated Virtual Classroom technical training, available to all active customers.
PATRICE
Top achievements
Rank 1
commented on 17 Nov 2022, 02:55 PM

Thank you Nikolay,

it solves the issue I had. I fixed my issue this way:

Grid column definition that is editable

               {
                    field: "time",
                    title: "@Localizer["Time"]",
                    width: 150,
                    template: "#= kendo.toString(time, 't') #",
                    editor: dateTimeEditor2
                }

 

from this:

 function dateTimeEditor2(container, options) {
        $('<input type="text" />')
            .appendTo(container)
            .kendoTimePicker({
                format: "HH:mm",
                value: kendo.toString(new Date(options.model.time), 'HH:mm')
            });
    }

 

to this:

 function dateTimeEditor2(container, options) {
        $('<input type="text" name="' + options.field +'"  id="' + options.field +'" />')
            .appendTo(container)
            .kendoTimePicker({
                format: "HH:mm",
                value: kendo.toString(new Date(options.model.time), 'HH:mm')
            });
    }
Anton Mironov
Telerik team
commented on 21 Nov 2022, 09:00 AM

Hi Patrice,

Thank you for sharing the approach with the community.

If further assistance is needed - do not hesitate to contact the team.

Kind Regards,
Anton Mironov

Tags
Grid
Asked by
Adil
Top achievements
Rank 1
Iron
Iron
Veteran
Answers by
Adil
Top achievements
Rank 1
Iron
Iron
Veteran
Nikolay
Telerik team
Share this question
or