stackoverflow demo: grid show colorpicker value
by Alex Yu
HTML
<script src="http://cdn.kendostatic.com/2013.2.918/js/kendo.all.min.js"></script>
<link rel="stylesheet" href="http://cdn.kendostatic.com/2013.2.918/styles/kendo.default.min.css">
<link rel="stylesheet" href="http://cdn.kendostatic.com/2013.2.918/styles/kendo.common.min.css">
<div style="width: 90%; height: 400px">
<table id="grid" style="width: 100%; heigth: 100%"></table>
</div>
JavaScript
var localData = [];
var someBool = true;
var someText = "#5b2f2f";
for (var i = 0, max_i = 100; i < max_i; i += 1) {
if (i > 10) {
someText = "#273362";
}
if (i > 20) {
someBool = false;
}
localData.push({
Id: i,
StatusText: someText,
someBool: someBool
});
if (i % 3 === 0) {
someBool = null;
someText = null;
} else {
someBool = !someBool;
someText = "#2a6227";
}
}
var dataSource = new kendo.data.DataSource({
data: localData,
schema: {
model: {
fields: {
Id: {
type: "number"
},
StatusText: {
type: "string"
},
someBool: {
type: "boolean"
}
}
}
}
});
var grid = $("#grid").kendoGrid({
dataSource: dataSource,
scrollable: false,
height: 500,
sortable: {
mode: "multiple"
},
filterable: true,
editable: true,
groupable: true,
columns: [{
field: "Id",
title: "Id",
filterable: false
}, {
field: "StatusText",
title: "String value",
editor: function (container, options) {
$("<input type='color' data-bind='value:" + options.field + "' />")
.appendTo(container)
.kendoColorPicker({
buttons: true
});
},
template: "<span style='display: inline-block; width: 100%; height: 100%; background-color: #= StatusText #'></span>"
}, {
field: "someBool",
title: "Boolean value"
}]
}).data("kendoGrid");