简体   繁体   中英

Kendo grid dropdownlist issue

I'm using a custom template on one of the column in my kendo grid. Everything is fine, when data retrieve, the dropdownlist show correct value. However when i click on edit command, the row become edit mode and the dropdownlist doesn't show its value. Only when i click on the dropdownlist, the item show selected. What I want is it show out the text when its in edit mode.

Before click edit 在此处输入图片说明

After click edit 在此处输入图片说明

My code:

function customDdlEditor(container, options) {
    $('<input required data-text-field="text" data-value-field="value"  data-bind="value:' + options.field + '"/>')//data-text-field="text" data-value-field="value" data-bind="value:fieldType"
   .appendTo(container)
   .kendoDropDownList({
       autobinds: false,
       dataTextField: "text",
       dataValueField: "value",           
       dataSource: ddl

   });
 }

var ddl = [{ text: "Text", value: "Text" },
        { text: "Date", value: "Date" },
        { text: "Number", value: "Number"}];

var Grid = $("#grid").kendoGrid({
            dataSource: fieldDataSource,                
            columns: [
        ...
        { field: "type", title: "Type", editor: customDdlEditor, template: "#= type #" },
        ...
        ,
            noRecords: true,
        }).data("kendoGrid");

        var fieldDataSource = new kendo.data.DataSource({
            data: gridData,
            pageSize: 50,
            schema: {
                model: {
                    id: "name",
                    fields: {
                        ...,
                        type: { field: "type"},
                        ...
                    }
                }
            }
        });

Anyone know how to solve this?

If you make your drop down autoBind: true should work.

function customDdlEditor(container, options) {
    $('<input required data-text-field="text" data-value-field="value"  data-bind="value:' + options.field + '"/>')//data-text-field="text" data-value-field="value" data-bind="value:fieldType"
   .appendTo(container)
   .kendoDropDownList({
       autobinds: true, // <-- auto bind true instead
       dataTextField: "text",
       dataValueField: "value",           
       dataSource: ddl

   });
 }

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