【问题标题】:Programmatically set dgrid row as active以编程方式将 dgrid 行设置为活动
【发布时间】:2013-07-23 23:10:02
【问题描述】:

我正在尝试以编程方式将 dgrid 行设置为 active,而不仅仅是 selected。我有一个使用SelectionKeyboard Mixins 的dojo dgrid OnDemandList

使用select(row) 方法,我可以以编程方式选择 给定行,但该行不是活动。当一行活动时,我可以使用向上和向下箭头键导航到其上方和下方的行。当一行只是选中时,该行会突出显示,但箭头键不起作用。

用鼠标单击该行将使其活动选中,但我正在尝试将我的界面构建为仅使用键盘即可100% 使用。

【问题讨论】:

    标签: dojo dgrid


    【解决方案1】:

    好的,花了我一段时间,但弄明白了。我真正想做的是将焦点添加到一行中。执行此操作的代码位于 dgrid/Keyboard.js 中的 _focusOnNode 方法下。

    将焦点从行 currentFocusedNode 更改为行 focusedNode 的实际代码是:

    if(currentFocusedNode){
        // Clean up previously-focused element
        // Remove the class name and the tabIndex attribute
        put(currentFocusedNode, "!dgrid-focus[!tabIndex]");
        if(has("ie") < 8){
            // Clean up after workaround below (for non-input cases)
            currentFocusedNode.style.position = "";
        }
    }
    
    if(has("ie") < 8){
        // setting the position to relative magically makes the outline
        // work properly for focusing later on with old IE.
        // (can't be done a priori with CSS or screws up the entire table)
        focusedNode.style.position = "relative";
    }
    focusedNode.tabIndex = grid.tabIndex;
    focusedNode.focus();
    put(focusedNode, ".dgrid-focus");
    

    上面的代码实际上只是一个代码片段,要使其工作,您必须先声明"dojo/has""put-selector/put",并定义currentFocusedNodefocusedNode。但我将把它作为练习留给读者;-)

    还要注意,这只会改变“焦点”,它不会选择focusedNode,但可以使用grid.select(focusedNode);轻松完成

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-01-30
      • 1970-01-01
      • 2011-11-19
      • 2017-02-18
      • 2011-08-23
      • 2018-02-02
      • 2019-10-28
      相关资源
      最近更新 更多