【问题标题】:extjs 6.2 grid, create columns from store dynamicallyextjs 6.2 网格,从商店动态创建列
【发布时间】:2019-03-10 02:32:41
【问题描述】:

在我的 extjs 6.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);
        }
    });

我认为我的问题是从我的商店创建列数组。如果我尝试手动操作,它会起作用……但我需要动态操作。

【问题讨论】:

    标签: dynamic grid extjs6


    【解决方案1】:

    使用商店的 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
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-10-01
      • 2012-05-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-12-21
      • 2012-06-15
      相关资源
      最近更新 更多