Search code examples
handsontable

Prevent Handsontable cells from being selected on column header click


In a Handsontable, when a column header is clicked, all cells of that column are selected. Is the a way to prevent this from happening ?

I don't think there's such an option in the documentation. I didn't find where the events are registered on the DOM within the source code of the Handsontable library itself either.

Any hint would be appreciated. Thanks.


Solution

  • It is possible to stop the event from propagating using the beforeOnCellMouseDown hook, which prevents the cells of the header column that was clicked to be selected:

    /**
     * @param {MouseEvent} event
     * @param {WalkontableCellCoords} coords
     * @param {Element} element
     */
    var handleHotBeforeOnCellMouseDown = function(event, coords, element) {
      if (coords.row < 0) {
        event.stopImmediatePropagation();
      }
    };
    
    Handsontable.hooks.add('beforeOnCellMouseDown',
        handleHotBeforeOnCellMouseDown, handsontable);
    

    A very special thanks to Gustavo for his help!