state.js 4.9 KB

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