我有一个简单的 handsontable,它从数据库中获取数据,但并非所有单元格都有数据,有些只有空值。除了 handsontable 在表中显示空单元格之外,是否可以在默认情况下放置一个值类似于 0.00 的数字格式化程序?
最佳答案
这是解决方案。如果不起作用,请检查并告诉我。我已经在 jsfiddle 上测试过了 > http://jsfiddle.net/yL8t1psf/1/
$(document).ready(function () {
var container = document.getElementById('basic_example');
var data = [
['', 'Kia', 'Nissan', 'Toyota', 'Honda'],
['2014', 10, 11, 12, 13],
['2015', 20, null, , 13],
['2016', null, 15,'', null]
];
var hot = new Handsontable(container, {
data: data,
height: 396,
colHeaders: true,
rowHeaders: true,
stretchH: 'all',
columnSorting: true,
contextMenu: true,
cells: function (row, col, prop,value) {
var cellProperties = {};
cellProperties.renderer = firstRowRenderer;
return cellProperties;
}
});
});
function firstRowRenderer(instance, td, row, col, prop, value, cellProperties) {
Handsontable.renderers.TextRenderer.apply(this, arguments);
if(!value || value === '' || value == null ) {
td.innerHTML = "0.00";
}
}
关于javascript - 如何为 Handsontable 中的所有空单元格提供默认值 0?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34042969/