<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Basic Demo</title>
<script src="https://www.jb51.net/jquery.min.js"></script>
<script src="https://www.jb51.net/jquery.handsontable.full.js"></script>
<link href="https://www.jb51.net/jquery.handsontable.full.css">
<script>
$(function(){
//数据
var data = [
{id: 1, name: "Ted", isActive: true, color: "orange"},
{id: 2, name: "John", isActive: false, color: "black"},
{id: 3, name: "Al", isActive: true, color: "red"},
{id: 4, name: "Ben", isActive: false, color: "blue"}
];
//黄色渲染方法
var yellowRenderer = function (instance, td, row, col, prop, value, cellProperties) {
Handsontable.TextCell.renderer.apply(this, arguments);
$(td).css({
background: 'yellow'
});
};
//绿色渲染方法
var greenRenderer = function (instance, td, row, col, prop, value, cellProperties) {
Handsontable.TextCell.renderer.apply(this, arguments);
$(td).css({
background: 'green'
});
};
//初始化
var $container = $("#example1");
$container.handsontable({
data: data,
startRows: 5,
colHeaders: true,
minSpareRows: 1,
columns: [
{data: "id"},
{data: "name", type: {renderer: yellowRenderer}}, //黄色渲染
{data: "isActive", type: Handsontable.CheckboxCell}, //多选框
{data: "color",
type: Handsontable.AutocompleteCell, //自动完成
source: ["yellow", "red", "orange", "green", "blue", "gray", "black", "white"] //数据源
}
],
cells: function (row, col, prop) {
if (row === 0 && col === 0) {
return {type: {renderer: greenRenderer}};
}
}
});
});
</script>
</head>
<body>
<div ></div>
</body>
</html>
您可能感兴趣的文章: