使用Angular Kendo UI的网格列中的模板和编辑器

时间:2014-05-26 15:33:48

标签: angularjs kendo-ui kendo-grid kendo-datasource

我试图在我的应用中使用Angular Kendo UI。有些观点包括网格。

  <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定义如下面的代码

    $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);
                }
            }
        }
    };

当我编辑网格项并单击&#34;保存更改&#34;按钮没有任何反应。
如果我定义没有编辑器的网格列,那么数据更新正确(这样我就必须使用默认的字符串编辑器)。但我需要定制编辑 我该如何解决这个问题?

1 个答案:

答案 0 :(得分:1)

尝试将name属性赋予编辑器输入,以便Grid知道要更新的模型的哪个属性。

input kendo-drop-down-list name='Account' ...