【问题标题】:How to Focus inthe First Cell of a Newly-Added Row in a dojox.grid.DataGrid如何关注 dojox.grid.DataGrid 中新添加行的第一个单元格
【发布时间】:2012-04-07 01:41:26
【问题描述】:

我正在向 dojox.grid.DataGrid 添加一个新的空白行,并希望将焦点放在新行的第一个单元格中。

我通过调用添加行:

var new_row = {},  
attributes = store.getAttributes( items[0] );

dojo.forEach( attributes, function( attribute )
{                   
    dojo.forEach( attributes, function( attribute )
    {
        new_row[ attribute ] = null;
    } );

} );

store.newItem( new_row );

我相信下面的代码会做焦点:

grid.focus.setFocusIndex( row_index, 0 );
grid.edit.setEditCell( grid.focus.cell, row_index );

但我不知道如何仅在重新渲染网格后调用此代码。我想我需要连接到一个事件。但是,我看不到可能使用的事件。 onNew() 似乎在添加新行之前被调用。

这是一个 JSFiddle,它尽可能接近解决方案。 http://jsfiddle.net/xDUpp/(注释掉标记为编辑的行并添加新行)

谢谢

【问题讨论】:

  • 嗨,在答案中查看我的解决方案,希望对您有所帮助。

标签: dojox.grid dojo


【解决方案1】:

您对哪个版本的 Dojo 感兴趣?

版本之间的 Dojo API 有所不同。在这件事上。

看: http://jsfiddle.net/keemor/xDUpp/11/

store修改后grid需要一点时间重建自身,所以setFocusIndex & setEditCell也必须延迟工作:

store.onNew = function( new_item ) {
    var rowIndex = new_item._0;                    
    window.setTimeout(function() {
        grid.focus.setFocusIndex( rowIndex, 0 );
        grid.edit.setEditCell( grid.focus.cell, rowIndex );
    },10);    

};

问候

【讨论】:

  • 谢谢基莫。我已根据您提供的内容在初始帖子中添加了一个 JSFiddle。
猜你喜欢
  • 1970-01-01
  • 2023-03-22
  • 1970-01-01
  • 1970-01-01
  • 2018-10-04
  • 2015-10-11
  • 1970-01-01
  • 1970-01-01
  • 2018-06-16
相关资源
最近更新 更多