有多種方法可以實現這一點。但是,細胞功能可能是最好的。
選項1
第1步:設置您的handsontable:
var container = document.getElementById('Element_ID');
hot = new Handsontable(container, {
data: <yourdataArray>,
autoRowSize:false,
autoWrapRow:true,
autoRowSize: false
});
第2步:更新使用細胞功能handsontable設置。細胞功能將通過每一行和單元表中的
// update spreadsheet setting
hot.updateSettings({
cells: function (row, col, prop) {
var cell = hot.getCell(row,col); // get the cell for the row and column
cell.style.backgroundColor = "#EEE"; // set the background color
}
});
選項2
我推薦的細胞功能過這一點,但是這並演示做同樣的事情的其他方式。
var hot = new Handsontable(document.getElementById('example1'), options);
var rows=hot.countRows(); // get the count of the rows in the table
var cols=hot.countCols(); // get the count of the columns in the table.
for(var row=0; row<rows; row++){ // go through each row of the table
for(var col=0; col<cols; col++){ // go through each column of the row
var cell = hot.getCell(row,col);
cell.style.background = "#00FF90";
}
}
hot.render(); // ensure the table is refreshed.
可能使用香草js? – levi
不知道如何識別我正在尋找的特定元素。 –
此外,這似乎沒有記錄:Handsontable.renderers.TextRenderer.apply –