我使用ExtJS的版本是4.2。我試圖保存網格的狀態,這是一個窗口的項目。當我關閉窗口時,網格的狀態保存在cookie中,但當窗口再次打開時,它不會恢復。我錯過了什麼?Extjs 4.2格的狀態在Ext.window.Window視圖中不恢復
這是我的代碼:
Ext.onReady(function() {
Ext.state.Manager.setProvider(Ext.create('Ext.state.CookieProvider'));
Ext.create('Ext.data.Store', {
storeId: 'simpsonsStore',
fields: ['name', 'email', 'phone'],
data: {
'items': [{
'name': 'Lisa',
"email": "[email protected]",
"phone": "555-111-1224"
}, {
'name': 'Bart',
"email": "[email protected]",
"phone": "555-222-1234"
}, {
'name': 'Homer',
"email": "[email protected]",
"phone": "555-222-1244"
}, {
'name': 'Marge',
"email": "[email protected]",
"phone": "555-222-1254"
}]
},
proxy: {
type: 'memory',
reader: {
type: 'json',
root: 'items'
}
}
});
Ext.create('Ext.container.Viewport', {
items: [
Ext.create('Ext.Button', {
text: 'Click me',
listeners: {
'click': function() {
var grid = Ext.create('Ext.grid.Panel', {
title: 'Simpsons',
store: Ext.data.StoreManager.lookup('simpsonsStore'),
columns: [{
text: 'Name',
dataIndex: 'name'
}, {
text: 'Email',
dataIndex: 'email',
flex: 1
}, {
text: 'Phone',
dataIndex: 'phone'
}],
stateful: true,
stateId: 'some_state_id'
});
var win = Ext.create('Ext.window.Window', {
title: 'Hello',
height: 200,
width: 900,
layout: 'fit',
items: grid
});
win.show();
}
}
})
]
});
})
這裏是小提琴:https://fiddle.sencha.com/#view/editor&fiddle/20sf
分配一個'id'或'stateId'到每一列和狀態信息的同時,再次創造了電網將重新應用。 –