1
votes

I added combobox to the Kendo Grid, as in the following example: http://demos.telerik.com/kendo-ui/grid/editing-custom

    schema: {
         data: "Data",
         total: "Total",
         errors: "Errors",
         model: {
             id: "Id",
             fields: {
                CityId: {
                  editable: true,
                  type: "number",
                  validation: { required: true }
                         }, ...

    columns: [{
         field: "CityId",
         title: "City",
         editor: cityDropDownEditor,
         template: "#=City.Name#",
         width: 200,
             } ...


             function cityDropDownEditor(container, options) {
                    $('<input required data-text-field="CityName" data-value-field="CityId" data-bind="value:' + options.field + '"/>')
                        .appendTo(container)
                        .kendoComboBox({
                        autoBind: true,
                        dataTextField: "CityName",
                        dataValueField: "CityId",
                        filter: "contains",
                        index: 1,
                        autocomplete: true,
                        dataSource: {
                            transport: {
                                read:
                                {
                                url: "/Contact/GetCities",
                                type: "POST",
                                dataType: "json"
                            }
                        }
                    }});                    
                }

And if I clicked to Add button, combobox is shown prefilled value 0. If i remove line type: "number" in schema - combobox shows prefilled value with CityName, index of which is set in the combobox initialization

.kendoComboBox({
 index: 1...

But when I click Submit, this value isn't got to the back-end and I see exception. How I can add correct default value for combobox?

1

1 Answers

0
votes

First as note you have dataTextField: "CityName", dataValueField: "CityId" twice initiated, and think you've missed something on your example which is this part in the schema

fields: {
    ProductID: { editable: false, nullable: true },
    ProductName: { validation: { required: true } },
    Category: { defaultValue: { CategoryID: 3, CategoryName: "Confections"} },
    UnitPrice: { type: "number", validation: { required: true, min: 1} }
 }

On the category field they set the default value to { CategoryID: 1, CategoryName: "Beverages"} , now i changed it to { CategoryID: 3, CategoryName: "Confections"}. It is working good here

DEMO