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

Grid - inline editing with custom editor template, no model value?

8 Answers 2867 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Mike
Top achievements
Rank 1
Mike asked on 29 Nov 2012, 03:25 PM
I am running into an issue with a simple string property when using a custom EditorTemplate in the Kendo Grid and inline editing.

I am doing something very similar to this: http://docs.kendoui.com/documentation/getting-started/using-kendo-with/aspnet-mvc/helpers/grid/editor-templates#create-custom-editor-for-a-bound-property

The issue appears to be that the model value for the property is not being passed to the editor template when entering edit mode. For example, if I remove the custom EditorTemplate usage, the grid works fine: clicking Edit shows a textbox for the string property with the saved value for the row prefilled in the textbox. When I use the custom EditorTemplate, the Model value is null. I've tried simplifying my editor template down to nothing but outputing the model value with the same results.

Any ideas of what might be causing this?

8 Answers, 1 is accepted

Sort by
0
Mike
Top achievements
Rank 1
answered on 29 Nov 2012, 07:42 PM
After trying some more things out, I tried setting the default value for the field that I'm using the custom EditorTemplate for, like so:

    .Model(model =>
    {
        model.Id(p => p.Id);
        model.Field(p => p.FooPropertyName).DefaultValue("TEST");
    })

When adding a record to the grid, this default string value of "TEST" does get passed to the EditorTemplate as the model value. However, when I have an existing row in the grid with a value for FooPropertyName, when entering Inline Edit mode, the value of TEST is still passed. Shouldn't the actual property value be passed in this case?

I'm using the latest release 2012.3.1114.
0
Daniel
Telerik team
answered on 03 Dec 2012, 12:28 PM
Hello Mike,

The model will be passed with the default values if you are using Ajax editing. Since the data is not available on the server the editor template will be serialized with the default values. The actual values will be populated for the item on the client using the MVVM pattern. If the value is not populated to the input in your case this, could be caused by using a name different than the field name. If this is not causing the problem a sample project which reproduces the issue would help to determine what exactly goes wrong.

Regards,
Daniel
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Mike
Top achievements
Rank 1
answered on 03 Dec 2012, 07:19 PM
Hi Daniel - 

Yes, this weekend I put together a sample program and haven't been able to duplicate the issue. Now, I'm trying to determine the cause of the problem in our project with no luck so far. I've verified that we're using the same jQuery version, Kendo js/css, etc. I also re-verified that the names are the same as the field names.

When we click an existing row to edit it, the combobox or dropdown columns do not have the current values prefilled. The dropdowns are populated, just the input with name "fieldname_input" that gets added upon clicking edit has no text in it. 
0
Mike
Top achievements
Rank 1
answered on 04 Dec 2012, 08:19 PM
Success!

I found the cause of the issue. Our problem was due to the inclusion of both kendo.all.min.js and kendo.dataviz.min.js. This hasn't caused any issues with any Kendo components before this, but removing kendo.dataviz.min.js solved the problem and now the Kendo ComboBox is properly displaying when editing inline in the Kendo Grid.


0
Neil
Top achievements
Rank 1
answered on 17 Jan 2013, 04:32 PM
Hi,

I have a similar issue in my project that I am having trouble solving; I have a grid wrapper, which uses ajax binding in the DataSource and I'm using a custom edit template to display various editors for the properties on the model associated with the grid.

Now, when using JavaScript in the editor template it's not possible to evaluate the VIewModel data, that is to say all the ViewModel properties have their default values. The problem as I understand it from Daniel's post is that since the custom editor template is processed on the server, no data for the model is present because is added to the template on the client after server processing is complete.

The documentation for EditorTemplates says that you can use the Html.EditorFor() helper which will display an editor for each model property, and this does work, unfortunately this seems to be the only method (besides .DefaultValue()) of getting model data into the custom template.

My question then is, will this ever be changed? I really need access to the ViewModel data - the EditorFor() helpers are useless to me as I need hidden fields to hold values that I can use in the template processing itself (e.g to determine whether to enable/disable controls etc), using the .DefaultValue() property of the Model.Field() is also useless as I need it to be respective to the record.

I hope there is a way I can have my cake and eat it too but I'm guessing my only option is to avoid the MVC wrapper and use the Kendo UI Web Grid instead, but I'd rather not have to scrap all my wrappers just because they won't play nice :)

Thanks,

Neil.

0
Daniel
Telerik team
answered on 21 Jan 2013, 11:59 AM | edited on 20 May 2021, 08:09 AM
Hi Neil,

There is no way to changed the behavior for Ajax binding because as mentioned in my previous reply the editor is serialized on the server and the data is loaded on the client. You could get the model that is currently in edit mode from JavaScript by using the Grid editable options e.g.

var grid = $("#Grid").data("kendoGrid");
var model = grid.editable.options.model;
Depending on the needed functionality, you could also use the MVVM bindings in the editor template to achieve it.

 Kind regards,
Daniel
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
serge
Top achievements
Rank 2
Bronze
Iron
Iron
commented on 15 May 2021, 10:27 AM

the link is invalid
Eyup
Telerik team
commented on 18 May 2021, 02:51 PM

Here is the new link which should be redirected by default:
https://docs.telerik.com/kendo-ui/framework/mvvm/bindings/attr
serge
Top achievements
Rank 2
Bronze
Iron
Iron
commented on 18 May 2021, 02:53 PM

"should be" :)
serge
Top achievements
Rank 2
Bronze
Iron
Iron
commented on 18 May 2021, 02:54 PM

better is to update the OP ;)
Eyup
Telerik team
commented on 20 May 2021, 08:10 AM

Updated.
0
Abhishek
Top achievements
Rank 1
answered on 05 Feb 2019, 08:50 AM

I have a similar issue. I have a MVC grid with editor template for all fields. I have cascading comboboxes for 2 fields.

In Inline Edit mode all fields get populated with existing values except the 2nd combobox of the cascading comboboxes (the one which depends on other for value). Also, a calendar in this doesnt'get populated if the date is today's date. This might be happening because of timezone difference between server and client browser because the value gets populated on IISexpress, but once on IIS server it doesn't get populated only for today's date. Grid date editor has defaultdate set to today's date and this is the code for DateEditor:   PS user cannot enter any future date.

@(Html.Kendo().DatePicker()

              .Name("Date")           
               .Max(DateTime.Today.Date)
              .HtmlAttributes(new { style = "width: 100%", title = "datepicker" })
              
)

 

 

 

0
Alex Hajigeorgieva
Telerik team
answered on 07 Feb 2019, 07:44 AM
Hello, Abhishek,

We have a project repository with cascading functionality that you may check at:

https://github.com/telerik/ui-for-aspnet-mvc-examples/tree/master/grid/grid-editing-cascading-dropdownlist

Have a look at the suggested approach and let me know how we can assist you further. It would be best if you could alter the project in such a way so that it better represents the exact scenario you have.

Also as far as the dates are concerned, you have a valid suspicion of the cause. We recommend keeping dates in UTC both on the client and the server to avoid issues with timezones:

https://docs.telerik.com/aspnet-mvc/helpers/grid/how-to/editing/utc-time-on-both-server-and-client

Kind Regards,
Alex Hajigeorgieva
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
Grid
Asked by
Mike
Top achievements
Rank 1
Answers by
Mike
Top achievements
Rank 1
Daniel
Telerik team
Neil
Top achievements
Rank 1
Abhishek
Top achievements
Rank 1
Alex Hajigeorgieva
Telerik team
Share this question
or