Success! Looks like we've fixed this one. According to our records the fix was applied for EXTJS-7893 in 4.2.2.1144.
  1. #1
    Sencha User
    Join Date
    May 2011
    Posts
    8
    Vote Rating
    1
    ericmash is on a distinguished road

      1  

    Default [4.0.2] Selection model returns wrong record when Grouping feature is enabled

    [4.0.2] Selection model returns wrong record when Grouping feature is enabled


    REQUIRED INFORMATION

    Ext version tested:
    • Ext 4.0.2
    Browser versions tested against:
    • Chrome 19.0.1084.46
    • FF 12.0
    DOCTYPE tested against:
    • ____
    Description:
    • Related to this post
    • The selection model of grid returns random record using getSelection() method when grouping feature is enabled
    • This cause a problem to drag and drop because Ext.view.DragZone.getDragData() is calling selectionModel.getSelection(). It results in random record being selected when dragging.
      (I actually find this bug through drag and drop, and find the problem with selection model through debugging)
    Steps to reproduce the problem:
    • Initialize a grid using grouping feature
    • Select some samples
    • Check the selection model and see if it returns the correct selection
    The result that was expected:
    • The record that is selected
    The result that occurs instead:
    • Random record
    Test Case:
    {Ext.view.DragZone}
    Code:
       
     getDragData: function(e) {        
          var view = this.view,
                item = e.getTarget(view.getItemSelector()),
                record, selectionModel, records;
    
    
            if (item) {
                record = view.getRecord(item);
                selectionModel = view.getSelectionModel();
                records = selectionModel.getSelection(); // THIS RETURNS WRONG  RECORDS
                return {
                    copy: this.view.copy || (this.view.allowCopy && e.ctrlKey),
                    event: new Ext.EventObjectImpl(e),
                    view: view,
                    ddel: this.ddel,
                    item: item,
                    records: records,
                    fromPosition: Ext.fly(item).getXY()
                };
            }
        }
    HELPFUL INFORMATION

    Operating System:
    • OSX 10.6.8

  2. #2
    Sencha User
    Join Date
    May 2011
    Posts
    8
    Vote Rating
    1
    ericmash is on a distinguished road

      0  

    Default


    I have found a fix for this bug. I am using Ext.override(), but the code can be easily inserted into the Ext.data.Store group(...) method.

    Code:
    Ext.override(Ext.data.Store, {
        /**
         * @override
         * The fix is to rearrange store.data so that it has the same order as the records in groups.
         * Multiple methods are using the order of store.data for finding the record.
         */
        group: function () {
            var store = this,
                groups;
    
    
            grid.getSelectionModel().deselectAll();
    
    
            store.callOverridden(arguments);
    
    
            groups = store.getGroups();
    
    
            store.data.clear();
    
    
            Ext.Array.each(groups, function (group) {
                Ext.Array.each(group.children, function (child) {
                    store.data.add(child.internalId, child);
                });
            });
    
    
            // update the view index after the store data is sorted by groups
            grid.getView().updateIndexes();
        }
    });

  3. #3
    Sencha - Support Team scottmartin's Avatar
    Join Date
    Jul 2010
    Location
    Houston, Tx
    Posts
    9,075
    Vote Rating
    467
    scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future

      0  

    Default


    Have you tried to see if this is a problem in 4.1? 4.02 is an old release and many issues have been addressed.

    Regards,
    Scott.

  4. #4
    Sencha User
    Join Date
    May 2011
    Posts
    8
    Vote Rating
    1
    ericmash is on a distinguished road

      0  

    Default


    I have only tested this bug in ExtJS 4.0.2. Our company is using Ext 4.0.2, and has no immediate to update to 4.1.
    I will setup a test environment for ExtJS 4.1 after coming back from vacation. I wonder if this bug is fixed if it is not logged before.

  5. #5
    Sencha User
    Join Date
    Sep 2011
    Posts
    8
    Vote Rating
    1
    jaimearmero is on a distinguished road

      1  

    Default Still a problem in 4.1

    Still a problem in 4.1


    Hello,
    same problem here with 4.1. It seems as if retrieval of selected item gets the item of the store which index is the index of the selected row, not the item which *data* is equals to data of the selected row. The problem is, order (and thus, indexes) may not be the same in grid and store. Example:

    STORE
    idx[0]: A
    idx[1]: B
    idx[2]: C

    GRID
    idx[0]: A
    idx[1]: C
    idx[2]: B

    We try to get selected the 2nd row of grid, this is, idx:1, data C. But it looks as if we really get idx:1 *of the store*, thus we get value B.

    Hope this could help to find a solution.
    Thank you very much,

    Jaime

  6. #6
    Sencha User
    Join Date
    Jul 2012
    Posts
    1
    Vote Rating
    0
    balabanmario is on a distinguished road

      0  

    Default


    We confirm the problem presence in 4.1
    We have a gridPanel that can be grouped and sorted by any column and it is bound to a remote store that has initial grouping and sorting:
    Code:
     Ext.define(storeName, {
             extend: 'Ext.data.Store',
             sorters: [{
                 property: 'createdAt',
                 direction: 'DESC'
             }],
             groupField: 'myField1',
             model: modelName
          });
    The problem is that after displaying the gridPanel with initial grouping and sorting and then doing another grouping by a second field ('myField2') and then reordering by a third field ('myField3') the elements in the gridPanel were displayed in the correct order and group.
    But after, selecting with the mouse every element of the gridPanel, we noticed that sometimes the selection(from the selectionModel) is not the one we have clicked.
    Debugging, we discovered that the problem is that the call
    Code:
    records = this.store.getRange(),
    in the function 'updateIndexes' of AbstractView.js was returning the records in a order that was different from the order of records displayed by the gridPanel and consequently the call to:
    Code:
    getRecord: function(node){
            return this.store.data.getByKey(Ext.getDom(node).viewRecordId);
        },
    in the same AbstractView.js was returning the wrong selected record.

    The porkarround solution was to override the sort function of the Store:
    Code:
    Ext.override(Ext.data.Store, {
          sort:function(){
             var me = this, groups, g;
    
    
    
    
             me.callOverridden(arguments);
             groups = me.getGroups();
    
    
             me.data.clear();
    
    
             Ext.Array.each(groups, function (group) {
                Ext.Array.each(group.children, function (child) {
                   me.data.add(child.internalId, child);
                });
             });
             me.fireGroupChange();
          }
       });
    Dear ExtJs Team, could you please include this case in the Test Suite? The grouping and filtering features should be considered like very important.

  7. #7
    Sencha Premium Member
    Join Date
    Nov 2008
    Posts
    61
    Vote Rating
    0
    nik600 is on a distinguished road

      0  

    Default


    We still have this problem with 4.1.1

  8. #8
    Sencha User
    Join Date
    Aug 2012
    Posts
    15
    Vote Rating
    0
    svper is on a distinguished road

      0  

    Default Help

    Help


    Can anyone please explain me where i put these pieces of code so this will work ?

    I have tried it in the grid file above the Ext.define

    if have tried it in the grid , in the store above the store ... nothing seems to work and i need it to work urgently


    using Extjs4.0

  9. #9
    Sencha User
    Join Date
    Apr 2008
    Location
    italy
    Posts
    8
    Vote Rating
    2
    satollo is on a distinguished road

      0  

    Default


    Since it is an override to a library method, should be placed immediately after loading ext but just before the start of your application.
    One solution is to copy the override code in a separate file and put it in this way:

    HTML Code:
    <script type="text/javascript" src="ext/ext-debug.js"></script>
    <script type="text/javascript" src="overrides.js"></script>
    <script type="text/javascript" src="app.js"></script>

  10. #10
    Sencha User
    Join Date
    May 2011
    Posts
    8
    Vote Rating
    1
    ericmash is on a distinguished road

      0  

    Default


    Ext.override can be called anywhere as long as it's being executed and ExtJS has be initialized. The way I do this is to create a plugin that initialized grouping, and execute the overide in the init method of the plugin

    Code:
    Ext.define('ISIS.plugin.GridGrouping', {
        extend: 'Ext.AbstractPlugin',
        requires: ['Ext.grid.feature.Grouping'],
    
        @override
        constructor: function () {
            var me = this,
                  grid = me.getCmp();
    
            me.callParent(arguments);
            grid.features.push(me.feature);
        },
    
        @override
        init: function () {
            // fix grouping feature
            Ext.override(Ext.data.Store, {
                ....... // the code to fix this bug
            );
        }
    }