Dev*_*Dev 9 extjs gridpanel extjs4.2
脚本
我想更新具有静态数据存储的网格中特定记录的列数据.这是我的商店:
extend : 'Ext.data.Store',
model : 'MyModel',
autoLoad:true,
proxy: {
type: 'ajax',
url: 'app/data/data.json',
reader: {
type: 'json',
root: 'users'
}
},
Run Code Online (Sandbox Code Playgroud)
我的data.json
{
'users': [{
QMgrStatus: "active",
QMgrName: 'R01QN00_LQYV',
ChannelStatus: 'active',
ChannelName: 'LQYV.L.CLNT',
MxConn: 50
}]
}
Run Code Online (Sandbox Code Playgroud)
我正在做什么来更新记录:
var grid = Ext.getCmp('MyGrid');
var store = Ext.getStore('Mystore');
store.each(function(record, idx) {
val = record.get('ChannelName');
if (val == "LQYV.L.CLNT") {
record.set('ChannelStatus', 'inactive');
record.commit();
}
});
console.log(store);
grid.getView().refresh();
Run Code Online (Sandbox Code Playgroud)
我的问题
我在这里更新记录.它没有反映在我的网格面板中.网格使用相同的旧存储(静态).是静态数据的问题?或者我错过了什么或者出错了?请帮我解决这个问题.非常感谢.
我的编辑
我尝试根据状态对列进行颜色编码.但是,即使我正在更新商店,我总是得到status ="active".
我想在网格中做什么
{
xtype: 'grid',
itemId: 'InterfaceQueueGrid',
id: 'MyGrid',
store: 'Mytore',
height: 216,
width: 600,
columns: [{
text: 'QueueMgr Status',
dataIndex: 'QMgrStatus',
width: 80
}, {
text: 'Queue Manager \n Name',
dataIndex: 'QMgrName',
width: 138
}, {
text: 'Channel Status',
dataIndex: 'ChannelStatus',
width: 78,
align: 'center',
renderer: function(value, meta, record) {
var val = record.get('ChannelStatus');
console.log(val); // Here I am always getting status="active".
if (val == 'inactive') {
return '<img src="redIcon.png"/>';
} else if (val == 'active') {
return '<img src="greenIcon.png"/>';
}
}
}, {
text: 'Channel Name',
align: 'center',
dataIndex: 'ChannelName',
width: 80
} {
text: 'Max Connections',
align: 'center',
dataIndex: 'MxConn',
width: 80
}]
}
Run Code Online (Sandbox Code Playgroud)
Chr*_*oph 10
一个重要的方法是重新配置您的网格.这可能不会最终成为您的最终解决方案,但也许您会知道出了什么问题.
呼叫
grid.reconfigure(store)
Run Code Online (Sandbox Code Playgroud)
代替
grid.getView().refresh();
Run Code Online (Sandbox Code Playgroud)
更改记录后.您还可以使用单个store.commitChanges(),而不是在每个记录上使用record.commit().
也许这只是一个错字,你在你的条件中分配val.试试这个(=到==):
var grid = Ext.getCmp('MyGrid');
var store = Ext.getStore('Mystore');
store.each(function(record,idx){
val = record.get('ChannelName');
if(val == "LQYV.L.CLNT"){
record.set('ChannelStatus','active');
}
else {
record.set('ChannelStatus','inactive');
}
record.commit();
});
console.log(store);
grid.getView().refresh();
Run Code Online (Sandbox Code Playgroud)
您是否尝试过提交您的商店并重新加载它?
试试这个方法。
yourstorename.commitChanges();
yourstorename.reload();
Run Code Online (Sandbox Code Playgroud)