最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to give default value of 0 to all the empty cells in Handsontable? - Stack Overflow

programmeradmin7浏览0评论

I have a simple handsontable, which get its data from a database, but not all the cells will have data,some will have just null values. Instead of handsontable showing the empty cell in the table, is it possible to put a number formatter with values like 0.00 by default??

I have a simple handsontable, which get its data from a database, but not all the cells will have data,some will have just null values. Instead of handsontable showing the empty cell in the table, is it possible to put a number formatter with values like 0.00 by default??

Share Improve this question edited Dec 2, 2015 at 14:26 Andrew Bone 7,3012 gold badges20 silver badges34 bronze badges asked Dec 2, 2015 at 12:38 Nikhil BharadwajNikhil Bharadwaj 9175 gold badges26 silver badges51 bronze badges 1
  • 1 might be good to make a jsfiddle just so we can see how far you've got. – Andrew Bone Commented Dec 2, 2015 at 13:50
Add a ment  | 

2 Answers 2

Reset to default 3

Here is solution. please check and let me know if not working. i have tested it on jsfiddle > http://jsfiddle/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";
    }    
  }

Add this into your conditional formatting.

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

if (!value || value === '') {
  td.innerHTML = "0.00";
}
发布评论

评论列表(0)

  1. 暂无评论