我有一个手持式网格(HandsonTable),并希望将导航限制在前两列(A、B)。因此,当用户在A1上启动并使用选项卡时,它将导航到B1、A2、B2、A3、B3等,并且当它到达表的末尾时,转到A1。
有办法这样做吗?
$(document).ready(function () {
var container = document.getElementById('basic_example');
var data = function () {
return Handsontable.helper.createSpreadsheetData(100, 12);
};
var hot = new Handsontable(container, {
data: data(),
height: 400,
colHeaders: true,
rowHeaders: true,
stretchH: 'all',
columnSorting: true,
contextMenu: true
});
});我的代码
发布于 2015-08-18 06:54:05
使用了上面的mpuraria提供的链接,并使它正常工作。在使用选项卡键时,导航顺序仅限于前两列。小提琴。
$(document).ready(function () {
var container = document.getElementById('basic_example');
var data = function () {
return Handsontable.helper.createSpreadsheetData(10, 9);
};
var hot = new Handsontable(container, {
data: data(),
height: 400,
colHeaders: true,
rowHeaders: true,
stretchH: 'all',
columnSorting: true,
contextMenu: true
});
Handsontable.Dom.addEvent(document.body, 'keydown', function(e) {
if (e.keyCode === 9) {
e.stopPropagation();
var selection = hot.getSelected();
var rowIndex = selection[0];
var colIndex = selection[1];
//rowIndex++;
colIndex++;
if (colIndex > 1) {
rowIndex++;
colIndex = 0;
}
hot.selectCell(rowIndex,colIndex);
}
});
});发布于 2020-02-28 23:09:54
我解决了这个问题:
afterDocumentKeyDown: function (event) {
// getSelected() returns [[startRow, startCol, endRow, endCol], ...]
const startRow = this.getSelected()[0][0];
if (event.key === "Tab") {
const nextRow = startRow === 6 ? 1 : startRow + 1; // if the last row (6), returns to the first one
this.selectCell(nextRow, 0); // needs to be col 0 because Tab already changes to the right col
}
}在我的例子中,我有一个表2列x7行,我打算只在第1列中从行(零索引)1移动到6,返回到第1行。
参考文献:
https://stackoverflow.com/questions/31422255
复制相似问题