首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >手持式设置自定义选项卡顺序

手持式设置自定义选项卡顺序
EN

Stack Overflow用户
提问于 2015-07-15 05:38:36
回答 2查看 889关注 0票数 0

我有一个手持式网格(HandsonTable),并希望将导航限制在前两列(A、B)。因此,当用户在A1上启动并使用选项卡时,它将导航到B1、A2、B2、A3、B3等,并且当它到达表的末尾时,转到A1。

有办法这样做吗?

代码语言:javascript
复制
$(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
  });

});

我的代码

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2015-08-18 06:54:05

使用了上面的mpuraria提供的链接,并使它正常工作。在使用选项卡键时,导航顺序仅限于前两列。小提琴

代码语言:javascript
复制
$(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);          
      }
    }); 
});
票数 1
EN

Stack Overflow用户

发布于 2020-02-28 23:09:54

我解决了这个问题:

代码语言:javascript
复制
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行。

参考文献:

  1. https://handsontable.com/docs/7.4.2/Hooks.html#event:afterDocumentKeyDown
  2. https://forum.handsontable.com/t/keyboard-tab-key-doesnt-enter-into-handsontable/3490
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/31422255

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档