Search code examples
javascriptjquerydojodojox.grid

regarding focus on row in enhanced grid


I want to focus on first cell of the newly created row in grid. Please suggest how can i make focus available on the newly added row in the grid on click of button.

store.onNew = function( new_item ) {
             var rowIndex = new_item._0;
             window.setTimeout(function() {
                grid.focus.setFocusIndex( rowIndex, 1 );
                grid.edit.setEditCell(grid.focus.cell, rowIndex );
            },0);   

I want to implement such a way that when user clicks on button , focus should automatically go the first cell of the newly created row and user should not scroll in order to see that. Please find the fiddle : http://jsfiddle.net/qKjm7/15/


Solution

  • You should use enhanced grid's scrollToRow function and pass in the row number that you want to scroll to, in your case it would be 0 for the first row.

    Example:

    grid.scrollToRow(0)
    

    I've also attached Fiddle demonstrating this here http://jsfiddle.net/kagant15/x9kLbqz5/