【问题标题】:Restricting selection to entire row/column in handsontable在handsontable中将选择限制为整行/列
【发布时间】:2015-08-31 16:00:47
【问题描述】:

我需要一种方法,只允许用户使用 handsontable 选择一行或一列(或多选整行和整列)。

【问题讨论】:

  • 永恒的问题,你试过什么?
  • 我已经回答了我自己的问题 :) 我认为分享一下会很好。

标签: javascript jquery handsontable


【解决方案1】:

经过一些研究和实验,我能够在没有单元格和行句柄的情况下实现单行突出显示。

Handsontable 选项:

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

CSS:

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

【讨论】:

    【解决方案2】:

    有一种方法可以通过设置选择多个单元格、范围单元格甚至单个单元格:selectionMode='multiple' 查看此链接:https://docs.handsontable.com/pro/3.0.0/Options.html#selectionMode

    【讨论】:

      【解决方案3】:

      我最终得到了这个解决方案:

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

      像魅力一样工作!

      【讨论】:

        猜你喜欢
        • 2013-10-31
        • 1970-01-01
        • 2015-04-17
        • 1970-01-01
        • 2011-03-17
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-09-12
        相关资源
        最近更新 更多