我在我的项目中使用handsontable。选择连续行,即使用 Shift 键选择多个连续行工作正常,但是当我尝试使用控制键选择随机行时,它不起作用。我被告知无法在handsontable 中选择多个随机行。
我们通过以下方式初始化handson构造函数:-
$element.handsontable({
columns:$scope.handsontable.columns,
data: $scope.handsontable.data,
colHeaders: $scope.handsontable.columnHeaders,
colWidths:$scope.handsontable.columnWidths,
readOnly:$scope.handsontable.readOnly,
fillHandle: false,
**currentRowClassName: 'currentRow',
currentColClassName: 'currentCol',**
variableRowHeights : false,
cells: function () {
this.renderer = $scope.gridConfiguration;
}
});
.css 类“currentRowClassName”和“currentColClassName”提供为:-
.handsontable .currentRow {
background-color: #66A3FF !important;
}
.handsontable .currentCol {
background-color: #F9F9FB;
}
在查看handsontable.js时,我发现了以下if block :-
if (priv.settings.currentRowClassName || priv.settings.currentColClassName) {
instance.view.wt.selections.highlight.clear();
instance.view.wt.selections.highlight.add(priv.selRange.from);
instance.view.wt.selections.highlight.add(priv.selRange.to);
}
我尝试注释掉它的第一行(instance.view.wt.selections.highlight.clear();
),这样选择就不会被清除,但即使这样也不起作用。
请帮助我使用handsontable选择随机(不一定是连续)行。谢谢
并尝试更改它,但没有任何效果
最佳答案
我认为 HOT 不支持这种选择,但您也许可以使用一些 DOM 操作来实现它。您可以尝试创建一个 .beforeMouseDown
事件,如果选择了 ctrl 键且未选择其他任何内容,则将当前所在的单元格附加到某个数组。
然后查看源代码,看看 Shift 是如何完成同样的事情的。我的猜测是,它说当按住 Shift 时,将 SelectedCells
设置为选择的开始和结束之间的所有单元格。您只需将其更改为仅开始和结束,而不是中间的事情。
关于javascript - 在handsontable中选择多个随机行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28558725/