代码之家  ›  专栏  ›  技术社区  ›  solarissf

extjs 6.2网格,从存储动态创建列

  •  0
  • solarissf  · 技术社区  · 6 年前

    在我的extjs6.2项目中,我试图从动态存储中为我的网格创建列。

                title: 'Data Viewer',
            xtype: 'grid',
            itemId: 'gridDataViewerId',
            bind: {
                store: '{storeData}'
            },
            ui: 'featuredpanel-framed',
            cls: 'custom-grid',            
            margin: '5',
            //frame: false,
            //forceFit: true,
            //height: '100%',
            flex: 1,
            plugins: [{
                ptype: 'gridexporter'
            }]
    

    加载存储后,我尝试创建列并填充数据,但它不起作用。你知道我做错了什么吗?

            this.storeData.load({
            url: x.util.GlobalVar.urlData_getData,
            params: {
                cid: cid,
                email: localStorage.getItem('username'),
                dateStart: targetStart,
                dateEnd: targetEnd,
                filename: targetFile
            },
            callback: function (response, opts) {
                debugger;
    
                var columnModel = me.storeData.data.items;                
                me.myGrid.reconfigure(me.storeData, columnModel);
            }
        });
    

    1 回复  |  直到 6 年前
        1
  •  1
  •   zeke    6 年前

    使用商店的 metachange 听众。比如:

    myStore.on('metachange', function(store, meta){
        myGrid.reconfigure(store, meta.columns);
    }
    

    {
        "records": [{
            "id": 74474,
            "name": "blah",
            "age": 5
        },{
            "id": 74475,
            "name": "asfdblah",
            "age": 35
        }],
        "totalRecords": 2,
        "metaData": {
            "fields": [{
                "name": "name"
            },{
                "name": "age",
                "type": "number"
            }],
            "columns": [{
                "text": "Name",
                "dataIndex": "name",
                "width": 150
            },
            {
                "text": "Age",
                "dataIndex": "age"
            }],
        },
        "success": true
    }