/ext-4.0.7/examples/layout/accordion.html

https://bitbucket.org/srogerf/javascript · HTML · 225 lines · 211 code · 13 blank · 1 comment · 0 complexity · 5abbd73390e14c6e6fbc4fdc6bf5b49c MD5 · raw file

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