要标记每个有更改的单元格,您可以创建一个自定义渲染器并仅在 data("change") 像这样存在时应用
//Custom renderer add class if the element have the data "change"
var myRenderer = function (instance, td, row, col, prop, value, cellProperties) {
Handsontable.TextCell.renderer.apply(this, arguments);
if($(td).data("change")){
$(td).addClass('changeInput');
}
};
$('#example').handsontable({
data: data,
minSpareRows: 1,
colHeaders: true,
contextMenu: true,
cells: function (row, col, prop) {//set the new renderer for every cell
return {type: {renderer: myRenderer}};
}
});
//afterChange get every cell and add class and data
$('#example').handsontable('getInstance').addHook('afterChange', function(changes) {
var ele=this;
$.each(changes, function (index, element) {
$(ele.getCell(element[0],element[1])).addClass('changeInput').data("change",true);
});
$("#example").on("keyup","textarea.handsontableInput",function (){
$(this).addClass('changeInput');
}).on("blur","textarea.handsontableInput",function (){
$(this).removeClass('changeInput');
});
http://jsfiddle.net/PAH5J/8/
编辑
移动突出显示的区域,您可以使用 cellProperties 而不是 .data() 像这样
var myRenderer = function (instance, td, row, col, prop, value, cellProperties) {
Handsontable.TextCell.renderer.apply(this, arguments);
if (cellProperties.change) {//check for new property change in the cell
$(td).addClass('changeInput'); //add the changeInput class to the actual td
}
};
$('#example1').handsontable('getInstance').addHook('afterChange', function(changes) {
var ele=this;
$.each(changes, function (index, element) {
//add the changeInput class to the actual td
$(ele.getCell(element[0],ele.propToCol(element[1]))).addClass('changeInput')
//get the cell properties and create a new one "change"
//to check in the renderer
ele.getCellMeta(element[0],ele.propToCol(element[1])).change=true;
});
});