state.js
4.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
Ext.require([
'Ext.grid.*',
'Ext.window.Window',
'Ext.container.Viewport',
'Ext.layout.container.Border',
'Ext.state.*',
'Ext.data.*'
]);
Ext.define('Person', {
extend: 'Ext.data.Model',
fields: ['first', 'last', 'review', {
name: 'age',
type: 'int'
}]
});
Ext.onReady(function(){
// setup the state provider, all state information will be saved to a cookie
Ext.state.Manager.setProvider(Ext.create('Ext.state.CookieProvider'));
Ext.create('Ext.container.Viewport', {
layout: {
type: 'border',
padding: '5'
},
items: [{
region: 'north',
styleHtmlContent: true,
height: 150,
bodyPadding: 5,
split: true,
html: [
'Between refreshes, the grid below will remember',
'<ul>',
'<li>The hidden state of the columns</li>',
'<li>The width of the columns</li>',
'<li>The order of the columns</li>',
'<li>The sort state of the grid</li>',
'</ul>'
].join(''),
dockedItems: [{
xtype: 'toolbar',
items: [{
text: 'Show window',
handler: function(btn){
Ext.create('Ext.window.Window', {
width: 300,
height: 300,
x: 5,
y: 5,
title: 'State Window',
maximizable: true,
stateId: 'stateWindowExample',
stateful: true,
styleHtmlContent: true,
bodyPadding: 5,
html: [
'Between refreshes, this window will remember:',
'<ul>',
'<li>The width and height</li>',
'<li>The x and y position</li>',
'<li>The maximized and restore states</li>',
'</ul>'
].join(''),
listeners: {
destroy: function(){
btn.enable();
}
}
}).show();
btn.disable();
}
}]
}]
}, {
bodyPadding: 5,
region: 'west',
title: 'Collapse/Width Panel',
width: 200,
stateId: 'statePanelExample',
stateful: true,
split: true,
collapsible: true,
html: [
'Between refreshes, this panel will remember:',
'<ul>',
'<li>The collapsed state</li>',
'<li>The width</li>',
'</ul>'
].join('')
}, {
region: 'center',
stateful: true,
stateId: 'stateGridExample',
xtype: 'grid',
store: Ext.create('Ext.data.Store', {
model: 'Person',
data: [{
first: 'John',
last: 'Smith',
age: 32,
review: 'Solid performance, needs to comment code more!'
}, {
first: 'Jane',
last: 'Brown',
age: 56,
review: 'Excellent worker, has written over 100000 lines of code in 3 months. Deserves promotion.'
}, {
first: 'Kevin',
last: 'Jones',
age: 25,
review: 'Insists on using one letter variable names for everything, lots of bugs introduced.'
}, {
first: 'Will',
last: 'Zhang',
age: 41,
review: 'Average. Works at the pace of a snail but always produces reliable results.'
}, {
first: 'Sarah',
last: 'Carter',
age: 23,
review: 'Only a junior, but showing a lot of promise. Coded a Javascript parser in Assembler, very neat.'
}]
}),
columns: [{
text: 'First Name',
dataIndex: 'first'
}, {
text: 'Last Name',
dataIndex: 'last'
}, {
text: 'Age',
dataIndex: 'age'
}, {
flex: 1,
text: 'Review',
dataIndex: 'review'
}]
}]
});
});