1. #1
    Ext JS Premium Member
    Join Date
    Jun 2011
    Location
    Ottawa, Ontario, Canada
    Posts
    123
    Vote Rating
    1
    Answers
    4
    whalethewise is on a distinguished road

      0  

    Question Unanswered: Simple task: Pre-select rows and focus first selected after store.loadData()

    Unanswered: Simple task: Pre-select rows and focus first selected after store.loadData()


    Simple task but gave me a lot of pain. When selection works fine - view.focusRow() or view.focusNode() is a killer. I ended up doing this, where focusOnSelect is a function of .mon
    Rows are selected but not focused without DelayedTask.
    I would appreciate any suggestions to simplify this if possible.

    PS. Just to clarify, I first create window with empty grid. Than I call store.loadData().

    Thanks

    Code:
    editAttrValuesGrid.mon(editAttrValuesGrid.getView(), 'refresh',editAttrValuesGrid.focusOnSelected, editAttrValuesGrid);

    Code:
       focusOnSelected: function (view) {
          if (this.selectedIndexes.length > 0)
          {
             var task = new Ext.util.DelayedTask(function (view) {
                var grid = view.ownerCt;
                view.focusRow(grid.selectedIndexes[0]);
                for (var i=0; i < grid.selectedIndexes.length; i++)
                {
                   grid.getSelectionModel().select(grid.selectedIndexes[i], true);
                }
                grid.selectedIndexes = [];
             });
             task.delay(500, null, null, [this.getView()]);
          }
       },

  2. #2
    Sencha User metalinspired's Avatar
    Join Date
    Apr 2012
    Posts
    98
    Vote Rating
    4
    Answers
    4
    metalinspired is on a distinguished road

      0  

    Default


    Have you setup mode of selection model to support multiple selections?

    Try this:
    Code:
     focusOnSelected: function (view) {
          if (this.selectedIndexes.length > 0)
          {
              var grid = view.ownerCt;
              grid.getSelectionModel().select(this.selectedIndexes);
              view.focusRow(grid.selectedIndexes[0]);
              //grid.selectedIndexes = [];    <----- not sure what you are trying to achieve here
           }
     },

  3. #3
    Ext JS Premium Member
    Join Date
    Jun 2011
    Location
    Ottawa, Ontario, Canada
    Posts
    123
    Vote Rating
    1
    Answers
    4
    whalethewise is on a distinguished road

      0  

    Default


    This is a first thing I tried because it is easiest. But didnt work for me.

    First, when you pass array of indexes into selectionModel.select () it doesnt select. Either one-by-one with indexes or array of model objects.
    Second, it doesnt focus. As soon as I use delayed task everything works.

  4. #4
    Sencha User metalinspired's Avatar
    Join Date
    Apr 2012
    Posts
    98
    Vote Rating
    4
    Answers
    4
    metalinspired is on a distinguished road

      0  

    Default


    You're right about select().
    Simple for() loop will suffice but add third param as true to suppress events.
    I don't know why focus() doesn't work because I'm using exact code that I pasted, in one of my apps, and if works just fine.

  5. #5
    Ext JS Premium Member
    Join Date
    Jun 2011
    Location
    Ottawa, Ontario, Canada
    Posts
    123
    Vote Rating
    1
    Answers
    4
    whalethewise is on a distinguished road

      0  

    Default


    focus works fine when I have Grid generated and loaded . And when after that I come and do focusRow() - no problem. But during loadData - I have a problem.

    So I ended up doing following:
    I mon() to 'datachanged' event where I do selection.
    And I mon() with delay to view 'refresh' event where I do focus.

    Code:
       editAttrValuesGrid.mon(editAttrsStore, 'datachanged',editAttrValuesGrid.storeLoaded, editAttrValuesGrid, {single: true});
       editAttrValuesGrid.mon(editAttrValuesGrid.getView(), 'refresh',editAttrValuesGrid.focusOnSelected, editAttrValuesGrid, {delay: 1,single: true});
    
    ......
    ......
       focusOnSelected: function (view) {
    
    
          if (this.selectedIndexes.length > 0)
          {
             this.getView().focusRow(this.selectedIndexes[0]);
          }
       },
       storeLoaded: function (store) {
    
    
          if (this.selectedIndexes.length > 0)
          {
             Ext.suspendLayouts();
             var view = this.getView();
             var grid = this;
             for (var i=0; i < grid.selectedIndexes.length; i++)
             {
                grid.getSelectionModel().select(grid.selectedIndexes[i]);
             }
             Ext.resumeLayouts(true);
          }
       },

  6. #6
    Sencha User metalinspired's Avatar
    Join Date
    Apr 2012
    Posts
    98
    Vote Rating
    4
    Answers
    4
    metalinspired is on a distinguished road

      0  

    Default


    This is a long shot, but have tried using on() instead of mon()?

  7. #7
    Ext JS Premium Member
    Join Date
    Jun 2011
    Location
    Ottawa, Ontario, Canada
    Posts
    123
    Vote Rating
    1
    Answers
    4
    whalethewise is on a distinguished road

      0  

    Default


    on() without delay on view 'refresh'?

  8. #8
    Sencha User metalinspired's Avatar
    Join Date
    Apr 2012
    Posts
    98
    Vote Rating
    4
    Answers
    4
    metalinspired is on a distinguished road

      0  

    Default


    try changing these two lines to on() with no delay and lets see if it has any effect
    Code:
       editAttrValuesGrid.mon(editAttrsStore, 'datachanged',editAttrValuesGrid.storeLoaded, editAttrValuesGrid, {single: true});   editAttrValuesGrid.mon(editAttrValuesGrid.getView(), 'refresh',editAttrValuesGrid.focusOnSelected, editAttrValuesGrid, {delay: 1,single: true});

  9. #9
    Sencha User
    Join Date
    Nov 2011
    Location
    Delhi
    Posts
    22
    Vote Rating
    0
    Answers
    2
    ashu2289 is on a distinguished road

      0  

    Default


    @whalethewise: Did you get any solution to this? I am also facing the similar issue.

Thread Participants: 2

Tags for this Thread