问题
I'm trying to use Angular Kendo UI in my app. Some views include grid.
<div kendo-grid
k-sortable ="true"
k-pageable ="true"
k-filterable ="true"
k-resizable ="true"
k-editable = "'incell'"
k-selectable = "true"
k-options = "accountSettingsDS"
k-columns = '[
{ field: "Companies", title: "Companies", editor : "<input kendo-drop-down-list k-data-text-field=\"'name'\" k-data-value-field=\"'name'\" k-data-source=\"CompaniesList\" ng-model=\"dataItem.Companies\"/>"},
{ field: "Currency", title: "Currency", editor : "<input kendo-drop-down-list k-data-text-field=\"'name'\" k-data-value-field=\"'name'\" k-data-source=\"CurrenciesList\" ng-model=\"dataItem.Currency\"/>"},
{ field: "Account", title: "Account", editor : "<input kendo-drop-down-list k-data-text-field=\"'name'\" k-data-value-field=\"'name'\" k-data-source=\"AccountsList\" ng-model=\"dataItem.Account\"/>"},
{ field: "NCAccount", title: "NCAccount", editor : "<input kendo-drop-down-list k-data-text-field=\"'name'\" k-data-value-field=\"'name'\" k-data-source=\"NCAccountsList\" ng-model=\"dataItem.NCAccount\"/>"}
]'
k-toolbar="['save','cancel']"
id="accountSettingsGrid">
</div
DataSource for this grid is defined like in code below
$scope.accountSettingsDS = {
dataSource: {
serverPaging: true,
serverFiltering: true,
serverSorting: true,
pageSize: 10,
type: "odata",
schema: {
data: function (response) {
if (response.value !== undefined)
return response.value;
else {
delete response["odata.metadata"];
return response;
}
},
total: function (response) {
return response['odata.count'];
},
model: {
id: "id",
fields: {
id: {
type: "number",
editable: false
},
Companies: {
type: "string",
editable: true
},
Currency: {
type: "string",
editable: true
},
Account: {
type: "string",
editable: true
},
NCAccount: {
type: "string",
editable: true
}
}
}
},
transport: {
read: {
url: serviceUrl + "AccountsSettings",
dataType: "json"
},
create: {
url: serviceUrl + "AccountsSettings",
type: "POST",
contentType: "application/json"
},
update: {
url: function(record) {
return serviceUrl + "AccountsSettings" + "(" + record.id + ")";
},
type: "PUT",
contentType: "application/json",
dataType: "json",
headers: { Prefer: "return-content" }
},
destroy: {
url: function(record) {
return serviceUrl + "AccountsSettings" + "(" + record.id + ")";
},
type: "DELETE",
contentType: "application/json",
dataType: "json"
},
parametermap: function (data, operation) {
console.log(data);
if (operation === "read") {
var parammap = kendo.data.transports.odata.parametermap(data);
return parammap;
}
return json.stringify(data);
}
}
}
};
When I edit grid item and click "Save changes" button nothing happens.
If I define grid columns without editors then data updates correctly(in this way I have to use default string editor). But I need custom editors.
How can I resolve this problem?
回答1:
Try to give name attribute to the editor input, so the Grid will know which property of the model to update.
input kendo-drop-down-list name='Account' ...
来源:https://stackoverflow.com/questions/23873490/using-templateseditors-in-grid-column-with-angular-kendo-ui