Restricting selection to entire row/column in handsontable

2.6k views Asked by At

I need a way to only allow the user to select a row or a column (or multiple selection of entire rows, and entire columns) using handsontable.

3

There are 3 answers

0
Diego Pamio On

I ended up with this solution:

beforeOnCellMouseDown: function restrictSelectionToWholeRowColumn(event, coords) {
  if(coords.row >= 0 && coords.col >= 0) event.stopImmediatePropagation();
}

works like charm!

0
John Fisher On

After a bit of research and experimentation, I was able to achieve single-row highlighting without the cell and row handles.

Handsontable options:

var x = new Handsontable(element, {
    ...
    multiSelect: false,
    disableVisualSelection: ['current', 'area'],
    currentRowClassName: 'currentRow'
}

CSS:

.currentRow, .highlight {
    background-color: lightblue;
}
0
Sagar On

There is an way to select multiple cells, range cells and even single cell by setting: selectionMode='multiple' checkout this link: https://docs.handsontable.com/pro/3.0.0/Options.html#selectionMode