dojox.grid - 如何聚焦在 dojox.grid.DataGrid 中新添加行的第一个单元格

标签 dojox.grid dojo

我正在向 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/ (注释掉标记为编辑的行并添加新行)

谢谢

最佳答案

您对哪个版本的 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);    

};

格雷茨

关于dojox.grid - 如何聚焦在 dojox.grid.DataGrid 中新添加行的第一个单元格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9823231/

相关文章:

javascript - Dojo 1.8 使用提供的 JsonRest 的对象和子对象填充 EnhancedGrid

javascript - 道场网格: accessing another attribute from a formatter

datagrid - Dojo Datagrid:如何更改第一行的样式?

带有 JSONREST 问题的 Dojo 增强型网格

php - 如何使dojo数据网格具有可编辑的行数据、可排序和分页

php - 用正斜杠转义 json 字符串?

javascript - 是否有一个工作 dojo tabContainer 可以在 contentPane 中成功重新加载?

gwt - 如何将 GWT 连接到 CometD/Bayeux 事件?

javascript - 道场店概念

dojo - 如何更改 Dojo 数据网格中的单个单元格值