我尝试以编程方式将dgrid行设置为活动,而不仅仅是选择。我有一个使用OnDemandList
和Selection
Mixins的dojo dgrid Keyboard
。
使用select(row)
方法,我可以通过编程方式选择给定行,但该行不是活动。当一行活动时,我可以使用向上和向下箭头键导航到它上面和下面的行。当一行只是选择时,该行会突出显示,但箭头键不起作用。
用鼠标单击该行将使其活动并选择 ,但我尝试使用键盘构建我的界面100%可用。
答案 0 :(得分: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"
,然后定义currentFocusedNode
和focusedNode
。但是我将这作为读者的练习; - )
另请注意,这只会更改“焦点”,但不会选择focusedNode
,但可以使用grid.select(focusedNode);
轻松完成