到有變化,你可以創建自定義渲染器和適用於僅當數據( 「變」)存在這樣
//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代替。數據()這樣的
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;
});
});
你需要使用事件委派,也許「KEYUP」,而不是改變[HTTP://的jsfiddle。 net/PAH5J/4 /](http://jsfiddle.net/PAH5J/4/) –
@AbrahamUribe我需要更改的TD保持黃色此外,這似乎隻影響textarea。 – triplethreat77
只適用於最後編輯的單元格[http://jsfiddle.net/PAH5J/6/](http://jsfiddle.net/PAH5J/6/) –