2012-03-22 37 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

相關問題