0

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/

1
  • Your fiddle isn't working properly. Click the "Add Row" button does nothing Commented Mar 25, 2015 at 12:58

1 Answer 1

1

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/

1
  • +1 Accepted the answer. I'm using pagination for my enhanced grid. The solution you suggested works fine when i'm adding new row in the same page, once the limit of the page is done, a new row is added in next page (pagination concept), the focus is going to the next page newly added row but issue is the field is not becoming editable as soon as it focus.User has to click on the new row in order to make it editable and below is the javascript error i'm seeing : Error: dojo.data.ItemFileWriteStore: Invalid item argument when new added row is in next page. Please suggest, thanks. @Thomas Kagan
    – user222
    Commented Mar 25, 2015 at 17:22

Not the answer you're looking for? Browse other questions tagged or ask your own question.