如何在dojox.grid.DataGrid中的新增行的第一个单元格中进行聚焦 [英] How to Focus inthe First Cell of a Newly-Added Row in a dojox.grid.DataGrid

查看:519
本文介绍了如何在dojox.grid.DataGrid中的新增行的第一个单元格中进行聚焦的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在向dojox.grid.DataGrid添加一个新的空白行,并且想要集中在新行的第一个单元格中。

I am adding a new blank row to a dojox.grid.DataGrid, and want to focus in the first cell of the new row.

我添加行通过调用:

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 );

我相信以下代码将进行重点:

I believe the following code will do the focusing:

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

但是,我无法弄清楚如何仅在网格重新呈现后才调用此代码。我想我需要连接到一个事件。但是,我看不到可能的事件使用。 onNew()似乎在添加新行之前被调用。

But I cannot figure out how to only call this code after the grid has re-rendered. I guess I need to connect to an event. However, I can't see a likely event to use. onNew() seems to be called before the new row is added.

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

Here's a JSFiddle which gets as close as I can to a solution. http://jsfiddle.net/xDUpp/ (comment out the line marked edit and it adds the new row)

谢谢

推荐答案

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

Which version of Dojo are you interested in?

Dojo API在ver之间有所不同。在这件事上。

The Dojo API differs between ver. in this matter.

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

存储修改后,网格需要一点时间来重建自己,所以setFocusIndex &安培; setEditCell也必须被延迟工作:

After store is modified grid needs a little time to rebuild itself, so setFocusIndex & setEditCell must also be delayed to work:

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);    

};

Greetz

这篇关于如何在dojox.grid.DataGrid中的新增行的第一个单元格中进行聚焦的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆