accordion.html 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. <html>
  2. <head>
  3. <title>Accordion Layout</title>
  4. <!-- Ext -->
  5. <link rel="stylesheet" type="text/css" href="../../resources/css/ext-all.css" />
  6. <!-- GC -->
  7. <style type="text/css">
  8. html, body {
  9. font: normal 12px verdana;
  10. margin: 0;
  11. padding: 0;
  12. border: 0 none;
  13. overflow: hidden;
  14. height: 100%;
  15. }
  16. .empty .x-panel-body {
  17. padding-top:20px;
  18. text-align:center;
  19. font-style:italic;
  20. color: gray;
  21. font-size:11px;
  22. }
  23. </style>
  24. <script type="text/javascript" src="../../ext-all.js"></script>
  25. <script type="text/javascript">
  26. Ext.require(['*']);
  27. Ext.onReady(function(){
  28. // sample static data for the store
  29. var myData = [
  30. ['3m Co', 71.72, 0.02, 0.03, '9/1 12:00am'],
  31. ['Alcoa Inc', 29.01, 0.42, 1.47, '9/1 12:00am'],
  32. ['Altria Group Inc', 83.81, 0.28, 0.34, '9/1 12:00am'],
  33. ['American Express Company', 52.55, 0.01, 0.02, '9/1 12:00am'],
  34. ['American International Group, Inc.', 64.13, 0.31, 0.49, '9/1 12:00am'],
  35. ['AT&T Inc.', 31.61, -0.48, -1.54, '9/1 12:00am'],
  36. ['Boeing Co.', 75.43, 0.53, 0.71, '9/1 12:00am'],
  37. ['Caterpillar Inc.', 67.27, 0.92, 1.39, '9/1 12:00am'],
  38. ['Citigroup, Inc.', 49.37, 0.02, 0.04, '9/1 12:00am'],
  39. ['E.I. du Pont de Nemours and Company', 40.48, 0.51, 1.28, '9/1 12:00am'],
  40. ['Exxon Mobil Corp', 68.1, -0.43, -0.64, '9/1 12:00am'],
  41. ['General Electric Company', 34.14, -0.08, -0.23, '9/1 12:00am'],
  42. ['General Motors Corporation', 30.27, 1.09, 3.74, '9/1 12:00am'],
  43. ['Hewlett-Packard Co.', 36.53, -0.03, -0.08, '9/1 12:00am'],
  44. ['Honeywell Intl Inc', 38.77, 0.05, 0.13, '9/1 12:00am'],
  45. ['Intel Corporation', 19.88, 0.31, 1.58, '9/1 12:00am'],
  46. ['International Business Machines', 81.41, 0.44, 0.54, '9/1 12:00am'],
  47. ['Johnson & Johnson', 64.72, 0.06, 0.09, '9/1 12:00am'],
  48. ['JP Morgan & Chase & Co', 45.73, 0.07, 0.15, '9/1 12:00am'],
  49. ['McDonald\'s Corporation', 36.76, 0.86, 2.40, '9/1 12:00am'],
  50. ['Merck & Co., Inc.', 40.96, 0.41, 1.01, '9/1 12:00am'],
  51. ['Microsoft Corporation', 25.84, 0.14, 0.54, '9/1 12:00am'],
  52. ['Pfizer Inc', 27.96, 0.4, 1.45, '9/1 12:00am'],
  53. ['The Coca-Cola Company', 45.07, 0.26, 0.58, '9/1 12:00am'],
  54. ['The Home Depot, Inc.', 34.64, 0.35, 1.02, '9/1 12:00am'],
  55. ['The Procter & Gamble Company', 61.91, 0.01, 0.02, '9/1 12:00am'],
  56. ['United Technologies Corporation', 63.26, 0.55, 0.88, '9/1 12:00am'],
  57. ['Verizon Communications', 35.57, 0.39, 1.11, '9/1 12:00am'],
  58. ['Wal-Mart Stores, Inc.', 45.45, 0.73, 1.63, '9/1 12:00am']
  59. ];
  60. /**
  61. * Custom function used for column renderer
  62. * @param {Object} val
  63. */
  64. function change(val) {
  65. if (val > 0) {
  66. return '<span style="color:green;">' + val + '</span>';
  67. } else if (val < 0) {
  68. return '<span style="color:red;">' + val + '</span>';
  69. }
  70. return val;
  71. }
  72. /**
  73. * Custom function used for column renderer
  74. * @param {Object} val
  75. */
  76. function pctChange(val) {
  77. if (val > 0) {
  78. return '<span style="color:green;">' + val + '%</span>';
  79. } else if (val < 0) {
  80. return '<span style="color:red;">' + val + '%</span>';
  81. }
  82. return val;
  83. }
  84. // create the data store
  85. var store = Ext.create('Ext.data.ArrayStore', {
  86. fields: [
  87. {name: 'company'},
  88. {name: 'price', type: 'float'},
  89. {name: 'change', type: 'float'},
  90. {name: 'pctChange', type: 'float'},
  91. {name: 'lastChange', type: 'date', dateFormat: 'n/j h:ia'}
  92. ],
  93. data: myData
  94. });
  95. // create the Grid
  96. var grid = Ext.create('Ext.grid.Panel', {
  97. hideCollapseTool: true,
  98. store: store,
  99. columnLines: true,
  100. columns: [
  101. {
  102. text : 'Company',
  103. flex : 1,
  104. sortable : false,
  105. dataIndex: 'company'
  106. },
  107. {
  108. text : 'Price',
  109. width : 75,
  110. sortable : true,
  111. renderer : 'usMoney',
  112. dataIndex: 'price'
  113. },
  114. {
  115. text : 'Change',
  116. width : 75,
  117. sortable : true,
  118. renderer : change,
  119. dataIndex: 'change'
  120. },
  121. {
  122. text : '% Change',
  123. width : 75,
  124. sortable : true,
  125. renderer : pctChange,
  126. dataIndex: 'pctChange'
  127. },
  128. {
  129. text : 'Last Updated',
  130. width : 85,
  131. sortable : true,
  132. renderer : Ext.util.Format.dateRenderer('m/d/Y'),
  133. dataIndex: 'lastChange'
  134. },
  135. {
  136. xtype: 'actioncolumn',
  137. width: 50,
  138. items: [{
  139. icon : '../shared/icons/fam/delete.gif', // Use a URL in the icon config
  140. tooltip: 'Sell stock',
  141. handler: function(grid, rowIndex, colIndex) {
  142. var rec = store.getAt(rowIndex);
  143. alert("Sell " + rec.get('company'));
  144. }
  145. }, {
  146. getClass: function(v, meta, rec) { // Or return a class from a function
  147. if (rec.get('change') < 0) {
  148. this.items[1].tooltip = 'Hold stock';
  149. return 'alert-col';
  150. } else {
  151. this.items[1].tooltip = 'Buy stock';
  152. return 'buy-col';
  153. }
  154. },
  155. handler: function(grid, rowIndex, colIndex) {
  156. var rec = store.getAt(rowIndex);
  157. alert((rec.get('change') < 0 ? "Hold " : "Buy ") + rec.get('company'));
  158. }
  159. }]
  160. }
  161. ],
  162. title: 'Array Grid (Click header to collapse)',
  163. viewConfig: {
  164. stripeRows: true
  165. }
  166. });
  167. var item1 = grid;
  168. var item2 = Ext.create('Ext.Panel', {
  169. title: 'Accordion Item 2',
  170. html: '&lt;empty panel&gt;',
  171. cls:'empty'
  172. });
  173. var item3 = Ext.create('Ext.Panel', {
  174. title: 'Accordion Item 3',
  175. html: '&lt;empty panel&gt;',
  176. cls:'empty'
  177. });
  178. var item4 = Ext.create('Ext.Panel', {
  179. title: 'Accordion Item 4',
  180. html: '&lt;empty panel&gt;',
  181. cls:'empty'
  182. });
  183. var item5 = Ext.create('Ext.Panel', {
  184. title: 'Accordion Item 5',
  185. html: '&lt;empty panel&gt;',
  186. cls:'empty'
  187. });
  188. var accordion = Ext.create('Ext.Panel', {
  189. title: 'Accordion',
  190. collapsible: true,
  191. region:'west',
  192. margins:'5 0 5 5',
  193. split:true,
  194. width: 210,
  195. layout:'accordion',
  196. items: [item1, item2, item3, item4, item5]
  197. });
  198. var viewport = Ext.create('Ext.Viewport', {
  199. layout:'border',
  200. items:[
  201. accordion, {
  202. region:'center',
  203. margins:'5 5 5 0',
  204. cls:'empty',
  205. bodyStyle:'background:#f1f1f1',
  206. html:'<br/><br/>&lt;empty center panel&gt;'
  207. }]
  208. });
  209. });
  210. </script>
  211. </head>
  212. <body>
  213. <script type="text/javascript" src="../shared/examples.js"></script><!-- EXAMPLES -->
  214. </body>
  215. </html>