I'm stumped on how to implement a foreign Key dropdownlist in a custom popup editor template for a grid. The scenario is quite common so I'm curious as to why I can't find an implementation of this. For example, say you have an Orders table with an inter column called CustomerId. This is a foreign key to a table called Customer, which also has the column CustomerName. Now I build a grid for orders and I want to use a custom popup editor template because I want to change the layout. How do I provide my user the ability to use a "Customer" dropdownlist that is populated with all the customers and id edit mode, is pre-selected to the current dataItems CustomerId?
I have tried creating a custom dropdown editor template with it's own datasource and it seems to work for the non-custom template, but it DOESN'T work for a custom one. How do you bind this? There does not appear to be an easy way to get to $scope to set the widget's datasource.
Environment: Kendo 2016.1.112, AngularJS v1.3.15, Windows 7 64bit, Google Chrome Version 38.0.2125.111 m
$scope.customers = new kendo.data.DataSource({
transport: {
read: {
url: 'api/customers',
dataType: 'json',
type: 'GET'
},
},
schema: {
model: {
id: "customerId",
fields: {
customerId: { type: "number" },
customerName: { type: "string" },
}
}
},
serverPaging: false,
}),
$scope.customerDropDownEditor = function customerDropDownEditor(container, options) {
//specify the value field in the "data-bind" attribute
$('<input required data-text-field="customerName" data-value-field="customerId" data-bind="value:customerId"/>')
.appendTo(container)
.kendoDropDownList({
autoBind: false,
dataSource: $scope.customers
});
},