I use ExtJS version is 4.2. I'm trying to save the state of a grid, which is item of a window. When I close the window, state of the grid is saved in cookies, but it doesn't get restored when window is opened again. What did I miss?
This is my code:
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();
}
}
})
]
});
})
Here is the fiddle: https://fiddle.sencha.com/#view/editor&fiddle/20sf
id
orstateId
to each of the columns and the state information will be reapplied while creating the grid again. – CS.