Results 1 to 7 of 7

Thread: 6.7.0 Modern Focus a row in a grid.

  1. #1
    Sencha User
    Join Date
    Sep 2007
    Location
    Phoenix AZ
    Posts
    119
    Answers
    5

    Default Answered: 6.7.0 Modern Focus a row in a grid.

    I am trying to allow arrow keys and enter key to navigate a grid in a dialog. I have to click with the mouse before I can use the keyboard.

    I am selecting the first row on refresh and that is working but the focus is not on that row or cell. I have to click with the mouse.

    Code:
    onGridRefresh: function(grid, eOpts) {
            var store = grid.getStore();
            if (store.getCount() > 0) {
                grid.select(store.getAt(0));
            }    
        }

    I got this from a forum post but this is the classic tool kit.

    Code:
    grid.getSelectionModel().setCurrentPosition({row:1, column:1});
    I need to set the focus to the first row first column and I can't figure out how to do this.

    Any assistance would be appreciated.

    -Mark

  2. This is not actually correct.

    Here is what I have been using most recently:

    Code:
     
    setFocusOnGrid: function(grid) {
            var store = grid.getStore();
            if (store !== null && store.getCount() > 0 ) {
                grid.select(store.getAt(0));
                var cell = grid.mapToCell(store.getAt(0), grid.getFirstVisibleColumn());
                var prevFocusable = cell.focusable;
                cell.focusable = true;
                var didSetFocus = cell.focus(false);
                cell.focusable = prevFocusable;
                return didSetFocus;
            }
            
        },


    Wow. Really easy.

    Just had to add grid.focus(record).

    Code:
     onGridRefresh: function(grid, eOpts) {
            var store = grid.getStore();
            if (store.getCount() > 0) {
                grid.select(store.getAt(0));
                grid.focus(store.getAt(0));
            }
        }

  3. #2
    Sencha User
    Join Date
    Sep 2007
    Location
    Phoenix AZ
    Posts
    119
    Answers
    5

    Default

    This is not actually correct.

    Here is what I have been using most recently:

    Code:
     
    setFocusOnGrid: function(grid) {
            var store = grid.getStore();
            if (store !== null && store.getCount() > 0 ) {
                grid.select(store.getAt(0));
                var cell = grid.mapToCell(store.getAt(0), grid.getFirstVisibleColumn());
                var prevFocusable = cell.focusable;
                cell.focusable = true;
                var didSetFocus = cell.focus(false);
                cell.focusable = prevFocusable;
                return didSetFocus;
            }
            
        },


    Wow. Really easy.

    Just had to add grid.focus(record).

    Code:
     onGridRefresh: function(grid, eOpts) {
            var store = grid.getStore();
            if (store.getCount() > 0) {
                grid.select(store.getAt(0));
                grid.focus(store.getAt(0));
            }
        }

  4. #3
    Sencha Premium User wemerson.januario's Avatar
    Join Date
    Nov 2008
    Location
    Goiânia - GO, Brazil
    Posts
    898
    Answers
    15

    Default

    Take a look at this method ensureVisible. It can be important for your needs

    https://docs.sencha.com/extjs/6.7.0/...-ensureVisible
    Wemerson Januario @JanuarioCoder
    Novanti Tecnologia, Sencha MVP/ Ext JS Consultant
    ____________________________________________
    Hire me on UpWork:

    GitHub
    https://github.com/wemersonjanuario

    Treinamento e Consultoria Ext JS. QUALIFIQUE-SE JÁ!

  5. #4
    Sencha User
    Join Date
    Sep 2007
    Location
    Phoenix AZ
    Posts
    119
    Answers
    5

    Default

    Thanks @wemerson.januario

    I will be sure to add this to my focus method.

  6. #5
    Sencha User
    Join Date
    Sep 2007
    Location
    Phoenix AZ
    Posts
    119
    Answers
    5

    Default

    Quote Originally Posted by wemerson.januario View Post
    Take a look at this method too ensureVisible. Can be important for your needs

    https://docs.sencha.com/extjs/6.7.0/...-ensureVisible

    Thanks for the suggestion. This is a much better solution.

    Code:
            var store = grid.getStore();
            if (store !== null && store.getCount() > 0 ) {
                grid.ensureVisible(0, {focus: true, select: true});
            }

  7. #6
    Sencha Premium User wemerson.januario's Avatar
    Join Date
    Nov 2008
    Location
    Goiânia - GO, Brazil
    Posts
    898
    Answers
    15

    Default

    You are welcome friend.

    if you think it is a better solution, please mark it as best answer. will help community
    Wemerson Januario @JanuarioCoder
    Novanti Tecnologia, Sencha MVP/ Ext JS Consultant
    ____________________________________________
    Hire me on UpWork:

    GitHub
    https://github.com/wemersonjanuario

    Treinamento e Consultoria Ext JS. QUALIFIQUE-SE JÁ!

  8. #7
    Sencha User
    Join Date
    Sep 2007
    Location
    Phoenix AZ
    Posts
    119
    Answers
    5

    Default

    I would like to ..... I wanted to add i to the answer post.... but for some reason it does not know it is me.... won't let me edit my post or change the answer.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •