2012-03-22 117 views
4

我正在向dojox.grid.DataGrid添加一个新的空行,并希望将焦点放在新行的第一个单元格中。如何关注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/(注释掉线标记编辑,并将其添加新行)

感谢

+1

嗨,在答案中签出我的解决方案,希望有所帮助。 – keemor 2012-04-14 22:56:04

回答

7

哪个版本的Dojo你有兴趣?

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

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

店被修改后电网需要一点时间来重建本身,因此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);  

}; 

格尔茨

+0

我正在使用1.6.1 - 谢谢。 voidstate – voidstate 2012-04-09 19:40:31

+0

谢谢keemor。我已经根据您提供的那个添加了一个JSFiddle到最初的帖子。 – voidstate 2012-04-11 15:31:08

相关问题