Search code examples
javascripthandsontable

Access cell alignment in Handsontable


As it can be tested in the align cell demo, handsontable supports cell alignment:

  • Horizontal
    • Left
    • Center
    • Right
    • Justify
  • Vertical
    • Top
    • Middle
    • Bottom

Here a screenshot:

handsontable screenshot

I can access the data with:

$('#table-wrapper').handsontable('getData')

But how can I access the cell alignment?


Solution

  • I think I found the solution. There is a cell method called getCellMeta. It returns an array containing an className entry.

    It can be accessed:

    var cellMeta = $('#table-wrapper').handsontable('getCellMeta', 0, 0);
    var className = cellMeta['className']; //String containing the information.
    

    Values are:

    • Horizontal
      • Left: htLeft
      • Center: htCenter
      • Right: htRight
      • Justify: htJustify
    • Vertical
      • Top: htTop
      • Middle: htMiddle
      • Bottom: htBottom

    Of course you can have a combination of two values (for horizontal and vertical) separated with a space.