Search code examples
javascripthandsontable

Handsontable: Getting HoT object in 'cells' function


I'm upgrading from an old version of HandsOnTable and I'm getting some problems getting the HoT object in the cells function, eg.:

cells: function (row, col, prop) {
            var cellProperties = {};
            cellProperties.className = 'htMiddle htCenter';



            if (hot.getDataAtRowProp(row, "Team") == "Boston Celtics")
                console.log("Celtics");




            return cellProperties;
        }

Uncaught TypeError: Cannot read property 'getDataAtRowProp' of undefined

Shouldn't the HoT object be available by then?

What I'm trying to do is to check the value of a specific cell to know if I should change the renderer of this column.

http://jsfiddle.net/b5kagLzx/


Solution

  • You're having scoping issues. You have access to the hot object by doing this.instance so just change your code to

    if (this.instance.getDataAtRowProp(row, "Team") == "Boston Celtics")
    

    That should work (it does in your fiddle)