Quantcast
Channel: Telerik Forums RSS
Viewing all articles
Browse latest Browse all 99250

Grid drop-down edit initial value (from row value)

$
0
0

Hello, 

 

I'm trying to get a grid with a column editing with a drop down list. I'm following this example, but although I get the values translated correctly and saved and loaded correctly, whenever I start editing the Drop-Down list doesn't have the value, as if it failed reading the current value from the row. 

 

Here is the relevant code snippets: 

 

Dictionary data source, translation helper and drop down callback: 

 

varpuDict = newkendo.data.DataSource({
        type: "json",
        transport: {
            read: {
                url: "getdict",
            }
        },
        schema: {
            model: {
                id: "code",
                fields: {
                    code: {nullable: false},
                    name: {nullable: false}
                }
            }
        }
    });
    puDict.fetch();
 
    functiontranslateType(type) {
        returnpuDict.get(type).name;
    }
     
    functiontypeDropDownEditor(container, options) {
        $('<input required data-text-field="name" data-value-field="code" data-bind="value:'+ options.field + '"/>')
                .appendTo(container)
                .kendoDropDownList({
                            autoBind: false,
                            dataSource: puDict
 
                        }
                )
    }

 

Here is the fields part of the grid: 

 

columns: [
                {field: "code", title: "Code (Unique)"},
                {field: "name", title: "Unit name"},
                {field: "type", title: "Unit type", editor: typeDropDownEditor, template: "#=translateType(type)#"},
                {command: ["edit", "destroy"], title: " "}
            ]

 

And `getdict` returns a JSON array that looks like this - 

[{
    "code": "TYPE1",
    "name": "Something of Type One"
},
{
    "code": "TYPE2",
    "name": "Something of Type Two"
}]

 

The grid shows the string "Something of Type One" and "Something of Type Two" correctly, so the translation works. Also, updating works correctly (and server side only knows about the code ("TYPE1", "TYPE2")), so the Drop Down also knows how to translate values back and forth. 

 

The only problem is that when I click on "edit", the dropdown is initially empty (nothing selected), instead of having the current value selected. 


Viewing all articles
Browse latest Browse all 99250

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>