How to focus in the first cell of a newly added row in dojox.grid.DataGrid

I add a new empty row to dojox.grid.DataGrid and want to focus in the first cell of the new row.

I add a line by calling:

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 focus:

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

But I can’t understand how to call this code only after re-rendering the grid. I think I need to connect to the event. However, I do not see a likely event to use. onNew () seems to be called before a new line is added.

Here's a JSFiddle that comes as close to the solution as possible. http://jsfiddle.net/xDUpp/ (comment out the highlighted line and add a new line)

thanks

+4
source share
1 answer

What version of Dojo are you interested in?

The Dojo API is different from ver. in this matter.

Take a look: http://jsfiddle.net/keemor/xDUpp/11/

After saving the modified mesh, it takes a little time to rebuild itself, so setFocusIndex and 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

+7
source

Source: https://habr.com/ru/post/1402893/


All Articles