Kendo Grid:如何添加颜色选择器

时间:2014-05-26 18:06:26

标签: javascript html kendo-ui kendo-grid kendo-colorpicker

我有一个带内联编辑的kendo网格。现在,在一列中,我想添加一个kendo颜色选择器。 如何在行未处于编辑模式时添加它并显示所选颜色?

任何人都可以在kendo网格中给我任何颜色选择器的例子吗?

由于

1 个答案:

答案 0 :(得分:4)

正如@dfsq所说,您必须使用单元格模板来显示颜色。此外,您需要为ColorPicker定义columns.editor

模板的代码是一个生成div的函数,其背景颜色是网格中的color值:

template:  function(dataItem) {
    return "<div style='background-color: " + dataItem.Color + ";'>&nbsp;</div>";
},

对于editor,您应该将函数定义为:

editor : function (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 ColorPicker
    input.kendoColorPicker({
        value: options.model.Color,
        buttons: false
    });
}

您可以在此处查看示例:http://jsfiddle.net/OnaBai/6XJV6/

相关问题