extjs动态存储模型网格列

63lcw9qa  于 2022-09-26  发布在  其他
关注(0)|答案(2)|浏览(175)

我有一个奇怪的问题。我正在设置一个存储并调用load函数。当存储加载时,我根据结果创建一个列模型,然后将该存储传递到网格并调用reconfigure()。网格看起来显示的行数正确,列标题正确,但单元格中的实际数据为空。但是,如果我调用grid.getStore()。在重新配置(这很糟糕,因为我已经加载了存储)之后,数据会正确显示。有人知道为什么会这样吗?下面是相关代码的片段。

dynStore.load({
        callback: function(records, operation, success) {
            if (records && records.length) {
                var dynStore = Ext.getStore('DynamicReportGeneratorResults');
                var modelFields = [];
                var dynamicColumns = [];
                var sampleRow = records[0].raw;
                Ext.Object.each(sampleRow, function (key, value) {
                    modelFields.push(key);
                    var dynColObj = {text: key, dataIndex: key};
                    if (key == "id") {
                        dynColObj.hidden = true;
                    }
                    dynamicColumns.push(dynColObj);
                });
                dynStore.model.setFields(modelFields);
                var config = {'reportName': this['currentReportName']};
                var reportResultWindow = Ext.create('Rms.view.DynamicReportGeneratorReportResultsWindow', config);
                reportResultWindow.show();
                this.getDynamicReportResultsGrid().reconfigure(dynStore, dynamicColumns);
/////*******  
//this next line is stupid since the store is already loaded with data
/////*******
                this.getDynamicReportResultsGrid().getStore().load();
            }
            else {
                Ext.Msg.alert("Report Resuts", "No results from this report");
        }
},
a9wyjsp7

a9wyjsp71#

为什么不使用加载数据方法?您拥有数据和所有内容,因此可以使用以下内容加载该数据:


# YOUR_STORE.loadData( records, false );

this.getDynamicReportResultsGrid().getStore().loadData( records, false );

参考sencha文档。

z6psavjg

z6psavjg2#

我有这个问题。我发现ExtJS中有一个bug,它在某些没有为网格指定高度的情况下隐藏了单元格数据。如果检查生成的实际HTML表,单元格数据实际上存在,但该表已指定position: absolute,这出于某种原因隐藏了单元格数据。
示例1隐藏单元格数据,未指定高度
http://codepen.io/anon/pen/azLWaV?editors=001

;(function(Ext) {
  Ext.onReady(function() {
    console.log("Ext.onReady")

    var store = Ext.create("Ext.data.Store", {
      fields: ["id", "name"]
      ,buffered: true
      ,pageSize: 100
      ,proxy: {
        type: 'rest'
        ,url: '/anon/pen/azLBeY.js'
        reader: {
          type: 'json'
        }
      }
    })
    store.on("load", function(component, records) {
      console.log("store.load")
      console.log("records:")
      console.log(records)
    })

    var grid = new Ext.create("Ext.grid.Panel", {
      requires: ['Ext.grid.plugin.BufferedRenderer']
      ,plugins: {
        ptype: 'bufferedrenderer'
      }
      ,title: "people"
      ,loadMask: true
      ,store: store
      ,columns: [
        {text: "id", dataIndex: "id"}
        ,{text: "name", dataIndex: "name"}
      ]
    })
    grid.on("afterrender", function(component) {
      console.log("grid.afterrender")
    })
    grid.render(Ext.getBody())

    store.load()
  })
})(Ext)

示例2可见单元格数据,指定高度
http://codepen.io/anon/pen/XJeNQe?editors=001

;(function(Ext) {
  Ext.onReady(function() {
    console.log("Ext.onReady")

    var store = Ext.create("Ext.data.Store", {
      fields: ["id", "name"]
      ,buffered: true
      ,pageSize: 100
      ,proxy: {
        type: 'rest'
        ,url: '/anon/pen/azLBeY.js'
        reader: {
          type: 'json'
        }
      }
    })
    store.on("load", function(component, records) {
      console.log("store.load")
      console.log("records:")
      console.log(records)
    })

    var grid = new Ext.create("Ext.grid.Panel", {
      requires: ['Ext.grid.plugin.BufferedRenderer']
      ,plugins: {
        ptype: 'bufferedrenderer'
      }
      ,title: "people"
      ,height: 200
      ,loadMask: true
      ,store: store
      ,columns: [
        {text: "id", dataIndex: "id"}
        ,{text: "name", dataIndex: "name"}
      ]
    })
    grid.on("afterrender", function(component) {
      console.log("grid.afterrender")
    })
    grid.render(Ext.getBody())

    store.load()
  })
})(Ext)

相关问题