After loading store, select and show specific row in grid works in Chrome, not in IE

血红的双手。 提交于 2019-12-06 15:13:43

The problem here is the asynchronous nature of the operations you are performing. There are two operations taking place at the same time here

  • Store load operation
  • Grid rendering

Your code attempts to select the 8th row from the grid after the store load event. But there is not guarantee that the grid has been rendered before the store loading operation have finished since the store has the autoLoad configuration value set to true. The reason this code works on Chrome and not on IE is because Chrome JavaScript engine is 10 times faster than IE 9 (IE 10 and 11 engines are also notoriously faster than IE 9) so your UI gets rendered before your loading operation gets finished. However this is just a matter of luck on having the sequence of events being triggered in the right order, to avoid this problem you should check the current store loading status after the UI has been rendered, and if it still loading you should deffer the select operation until the store has been loaded, something like:

// create the Grid
var grid = new Ext.grid.GridPanel({
    store: store,
    id: 'grid',
    columns: [{
        header: 'Company',
        dataIndex: 'Company'
    }, {
        header: 'First name',
        dataIndex: 'First'
    }, {
        header: 'Last name',
        dataIndex: 'Last'
    }, {
        header: 'Email',
        dataIndex: 'Email'
    }],
    height: 150,
    listeners: {
        'render': function(component) {
            // Get sure that the store is not loading and that it 
            // has at least a record on it
            if (grid.store.isLoading() || grid.store.getCount() == 0) {
                // If it is still pending attach a listener to load
                // event for a single time to handle the selection
                // after the store has been loaded
                grid.store.on('load', function() {
                    grid.getView().getSelectionModel().select(0);
                    grid.getView().focusRow(0);
                }, this, {
                    single: true
                });
            } else {
                grid.getView().getSelectionModel().select(0);
                grid.getView().focusRow(0);
            }

        }
    }
});

You can see a full working example based on your code here. Hope this helps.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!