Using templates&editors in grid column with Angular Kendo UI

霸气de小男生 提交于 2019-12-10 11:45:44

问题


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=\"&#39;name&#39;\" k-data-value-field=\"&#39;name&#39;\" k-data-source=\"CompaniesList\" ng-model=\"dataItem.Companies\"/>"},
         { field: "Currency", title: "Currency", editor : "<input kendo-drop-down-list k-data-text-field=\"&#39;name&#39;\" k-data-value-field=\"&#39;name&#39;\" k-data-source=\"CurrenciesList\" ng-model=\"dataItem.Currency\"/>"},
         { field: "Account", title: "Account", editor : "<input kendo-drop-down-list k-data-text-field=\"&#39;name&#39;\" k-data-value-field=\"&#39;name&#39;\" k-data-source=\"AccountsList\" ng-model=\"dataItem.Account\"/>"},
         { field: "NCAccount", title: "NCAccount", editor : "<input kendo-drop-down-list k-data-text-field=\"&#39;name&#39;\" k-data-value-field=\"&#39;name&#39;\" 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!