Kendo Grid:如何在列中添加KendoColorPicker

时间:2014-06-10 16:31:44

标签: javascript jquery angularjs kendo-ui kendo-grid

在angularjs中我有kendo ui网格,我必须有一个列,一列必须是colorPicker:所以我输入以下代码:

$scope.thingsOptions = {
    sortable: "true",
    scrollable: "true",
    toolbar: [{ name: "create", text: "Aggiungi Profilo Tessera" }],
    columns: [
                { field: "Name", title: "Name", width: "50px" },
                { field: "Description", title: "Description", width: "150px" },
                {
                    field: "Color", title: "Color", width: "50px", editor: colorDropDownEditor, template: function (dataItem) {
                        return "<div style='background-color: " + dataItem.Color+ ";'>&nbsp;</div>";
                    }
                },

                { command: [{ name: "edit", text: "Modifica" }], title: "", width: "100px" }
    ],
    editable: "inline"
};

function colorDropDownEditor(container, options) {
    // create an input element
    var input = $("<input/>");
    // set its name to the field to which the column is bound ('name' in this case)
    input.attr("name", options.field);
    // append it to the container
    input.appendTo(container);
    // initialize a Kendo UI AutoComplete
    input.kendoColorPicker({
        palette: 'basic',
        value: "#000000",
        buttons: false
    });
}

问题是当我添加一个新行时,我在javascript控制台中看到以下错误:

Uncaught Error: Cannot parse color:

我无法创建新行。我该如何解决这个问题?

1 个答案:

答案 0 :(得分:1)

您应指定颜色字段的默认值,否则颜色选择器将尝试将“未定义”解析为有效颜色。

$scope.thingsOptions = {
    dataSource: {
       schema: {
          model: {
            fields: {
              Color: { defaultValue: "#000" }
            }
          }
       }
    },
    /* snip */
}