我有一个奇怪的问题。我正在建立一个商店并调用加载功能。当商店加载时,我根据结果创建一个列模型,然后将该商店传递到网格中并调用reconfigure()。网格看起来显示了正确的行数,列标题是正确的,但单元格中的实际数据是空白的。但是,如果我在重新配置之后调用grid.getStore()。load()(因为我已经加载了存储而很糟糕),数据会正确显示。有人知道为什么会这样吗?下面是相关代码的片段。
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");
}
},
答案 0 :(得分:0)
为什么不使用加载数据方法? 你有数据和所有东西,所以加载数据:
#YOUR_STORE.loadData( records, false );
作为
this.getDynamicReportResultsGrid().getStore().loadData( records, false );
参考sencha docs。
答案 1 :(得分:0)
我遇到了这个问题。我发现ExtJS中有一个错误,在某些没有为网格指定高度的情况下隐藏了单元格数据。如果检查生成的实际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)