Javascript 如何设置手持设备中每个单元格的背景色?
我有一个可触摸的表格,希望设置每个单元格的背景颜色,而不提供渲染器功能或类似功能。我尝试复制它们使用的进程,但是我的表中的值有格式,并且它们的渲染器函数代码丢失了格式 渲染器的我的版本:Javascript 如何设置手持设备中每个单元格的背景色?,javascript,css,handsontable,Javascript,Css,Handsontable,我有一个可触摸的表格,希望设置每个单元格的背景颜色,而不提供渲染器功能或类似功能。我尝试复制它们使用的进程,但是我的表中的值有格式,并且它们的渲染器函数代码丢失了格式 渲染器的我的版本: var footerRenderer = function(instance, td, row, col, prop, value, cellProperties) { Handsontable.renderers.TextRenderer.apply(this, arguments); td.
var footerRenderer = function(instance, td, row, col, prop, value, cellProperties) {
Handsontable.renderers.TextRenderer.apply(this, arguments);
td.style.backgroundColor = '#EEE';
td.style.textAlign = 'right';
}
澄清一下:这里的问题是,当需要更改单元格的背景颜色等简单操作时,使用具有HandsOnTable的渲染器函数似乎会删除表属性应用的格式设置。有多种方法可以实现这一点。然而,细胞的功能可能是最好的 选项1 步骤1:设置您的掌上电脑:
var container = document.getElementById('Element_ID');
hot = new Handsontable(container, {
data: <yourdataArray>,
autoRowSize:false,
autoWrapRow:true,
autoRowSize: false
});
选项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.
var hot=new Handsontable(document.getElementById('example1'),选项);
var rows=hot.countRows();//获取表中的行数
var cols=hot.countCols();//获取表中列的计数。
对于(var row=0;row)是否可以使用vanilla js?不确定如何识别我正在寻找的一个特定元素。此外,这似乎没有记录在案:Handsontable.renderers.textrender.apply
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.