我有一个简单的handsontable,它从数据库获取数据,但并不是所有的单元格都有数据,有些只有空值。是否可以在handsontable中设置数字格式,使得默认显示0.00而不是空单元格?
我有一个简单的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";
}
}
http://docs.handsontable.com/0.20.0/demo-conditional-formatting.html
if (!value || value === '') {
td.innerHTML = "0.00";
}
value=0
或者是一个布尔值,会怎么样? - ZekeDroid