Search code examples
javascripthandsontable

How to do conditional formatting on Handsontable?


var data = [
    ["", "Tesla", "Volvo", "Toyota", "Honda"],
    ["2017", 10, 11, 12, 13],
    ["2018", 20, 11, 14, 13],
    ["2019", 30, 15, 12, 13]
];

var container = document.getElementById('example');
var hot = new Handsontable(container, {
    data: data,
    rowHeaders: true,
    colHeaders: true
});

Here is sample Handsontable. I want to change first rows text formatting. e.g bold

I think cells callback function will help but I am not sure what are parameters and how to use that.

cells: function (row, col, prop) {
    var cellProperties = {};
    if (row === 0) {
         cellProperties.renderer = function () {
             ...
         }
    }
}

Thanks.


Solution

  • cells: function(td, row, col, prop) {
        var cellProperties = {};
        if (row > 0 && col > 0) {
            cellProperties.type = 'numeric',
                cellProperties.format = '0,0.00 $';
            cellProperties.renderer = celulasBold;
        }
        return cellProperties;
    }
    

    I can used this callback and this makes me to work with cell formatting. If any visitors who met problem like this please ask. Thanks.