extjs grid中columns用到的store未初始化完成的解决办法

使用extjs 开发grid的时候,如果某列的editor是store ,在store没有完成加载的时候,加载list数据,可能出现

该列不显示的问题,如下

{
    header: '站点', dataIndex: 'stationId', flex: 1,
    renderer: function (value) {
        var store = stationStore;
        var record = store.queryBy(function (rec) {
            if (rec.data.code == value) {
                return true;
            }
        }, this);
        if (record.getCount() == 1) {
            return record.get(0).data.name;
        }
    },
    editor: {
        columnWidth: 1,
        xtype: 'combobox',
        typeAhead: true,
        editable: true,
        queryMode: 'local',
        valueField: "code",
        displayField: 'name',
        forceSelection: true,
        store: stationStore
}
},
第一次加载页面的时候,容易出现该列不显示的问题,解决办法如下
先设置list的store autoLoad:false
列中用到的store 加载完成后再调用list.getStore().reload().
var coalTypeStore = Ext.create('Ext.data.Store', {
    autoLoad: true,
    fields: [{name: "name", type: "string"},
        {name: "code", type: "string"}],
    proxy: {
        // async: false,
type: 'ajax',
        url: ',
        reader: {
            type: 'json',
            root: 'records'
}
    },
    listeners: {
        'load': function () {
            if (stationStore.getCount() > 0) {
//其他store是否加载完成 
                Ext.getCmp('xx').getStore().load();
            }
        }
    }
});

猜你喜欢

转载自201305070711.iteye.com/blog/2353427