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:
var
puDict =
new
kendo.data.DataSource({
type:
"json"
,
transport: {
read: {
url:
"getdict"
,
}
},
schema: {
model: {
id:
"code"
,
fields: {
code: {nullable:
false
},
name: {nullable:
false
}
}
}
}
});
puDict.fetch();
function
translateType(type) {
return
puDict.get(type).name;
}
function
typeDropDownEditor(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.