Tom*_*Tom 2 html javascript kendo-ui kendo-grid kendo-colorpicker
我有一个带编辑内联的剑道网格。现在,在一列中,我想添加一个剑道颜色选择器。当行未处于编辑模式时,如何添加它并显示所选颜色?
任何人都可以给我举个剑道网格中颜色选择器的例子吗?
谢谢
正如@dfsq 所说,您必须使用单元格模板来显示颜色。此外,您需要columns.editor为ColorPicker.
模板的代码是一个函数,它生成一个div背景颜色是color来自网格的值:
template: function(dataItem) {
return "<div style='background-color: " + dataItem.Color + ";'> </div>";
},
Run Code Online (Sandbox Code Playgroud)
对于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
});
}
Run Code Online (Sandbox Code Playgroud)
你可以在这里看到一个例子:http : //jsfiddle.net/OnaBai/6XJV6/