我有一个由数据填充并已经呈现的Handsontable
在检查了这些单元格之后,我找到了几个感兴趣的单元格,并希望给它们着色--使用Handsontable代码是否有一个很好的方法来做到这一点?
请注意,这是在加载和呈现表之后。
编辑:
该表使用基本选项呈现:
$container.handsontable({
startRows: 8,
startCols: 6,
rowHeaders: true,
colHeaders: true,
minSpareRows: 1,
minSpareCols: 1,
//contextMenu: false,
cells: function (row, col, prop) {
}
});数据通过Ajax加载,decode_file.php读取excel表并以JSON的形式返回数据:
$.ajax({
url: "decode_file.php",
type: 'GET',
success: function (res) {
handsontable.loadData(res.data);
console.log('Data loaded');
},
error: function (res) {
console.log("Error : " + res.code);
}
});加载数据后,用户单击"Process“按钮,代码将查找带有文本"Hello”的单元格。假设代码在单元格第4行/第5行中找到文本"Hello“,并将单元格第4行/第5行的背景色更改为red
发布于 2013-03-04 10:02:27
主页为您提供了一个很好的示例:
http://handsontable.com/demo/renderers.html
只需修改条件(在本例中是左上角)。
cells: function (row, col, prop) {
if (row === 0 && col === 0) {
return {type: {renderer: greenRenderer}};
}
}你就完蛋了。
发布于 2013-06-05 16:51:02
- for cells within the selected coordinates, apply the chosen renderer and update the renderer's name in the 2.a. array
- for all other cells, apply the stored renderer
发布于 2015-09-16 14:20:06
一种我正在使用的有点奇怪的方法,它实际上运行得很快并且工作得很好:
afterRender: function(){
render_color(this);
}ht是handsontable的实例,render_color:
function render_color(ht){
for(var i=0;i<ht.countRows();i++){
for(var p=0;p<ht.countCols();p++){
cell_color = "#000";
font_color = "#fff";
$(ht.getCell(i,p)).css({"color": font_color, "background-color": cell_color})
}
}
}https://stackoverflow.com/questions/14530375
复制相似问题