如何为 Handsontable 中的所有空单元格提供默认值 0?

How to give default value of 0 to all the empty cells in Handsontable?

我有一个简单的 handsontable,它从数据库中获取数据,但并非所有单元格都有数据,有些只有空值。而不是 handsontable 在 table 中显示空单元格,是否可以放置一个默认值为 0.00 的数字格式化程序?

将此添加到您的条件格式中。

http://docs.handsontable.com/0.20.0/demo-conditional-formatting.html

if (!value || value === '') {
  td.innerHTML = "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";
    }    
  }