grid-plugins.js 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. Ext.Loader.setConfig({
  2. enabled: true
  3. });
  4. Ext.Loader.setPath('Ext.ux', '../ux');
  5. Ext.require([
  6. 'Ext.grid.*',
  7. 'Ext.data.*',
  8. 'Ext.ux.RowExpander',
  9. 'Ext.selection.CheckboxModel'
  10. ]);
  11. Ext.onReady(function(){
  12. Ext.define('Company', {
  13. extend: 'Ext.data.Model',
  14. fields: [
  15. {name: 'company'},
  16. {name: 'price', type: 'float'},
  17. {name: 'change', type: 'float'},
  18. {name: 'pctChange', type: 'float'},
  19. {name: 'lastChange', type: 'date', dateFormat: 'n/j h:ia'},
  20. {name: 'industry'},
  21. {name: 'desc'}
  22. ]
  23. });
  24. // Array data for the grids
  25. Ext.grid.dummyData = [
  26. ['3m Co',71.72,0.02,0.03,'9/1 12:00am', 'Manufacturing'],
  27. ['Alcoa Inc',29.01,0.42,1.47,'9/1 12:00am', 'Manufacturing'],
  28. ['Altria Group Inc',83.81,0.28,0.34,'9/1 12:00am', 'Manufacturing'],
  29. ['American Express Company',52.55,0.01,0.02,'9/1 12:00am', 'Finance'],
  30. ['American International Group, Inc.',64.13,0.31,0.49,'9/1 12:00am', 'Services'],
  31. ['AT&T Inc.',31.61,-0.48,-1.54,'9/1 12:00am', 'Services'],
  32. ['Boeing Co.',75.43,0.53,0.71,'9/1 12:00am', 'Manufacturing'],
  33. ['Caterpillar Inc.',67.27,0.92,1.39,'9/1 12:00am', 'Services'],
  34. ['Citigroup, Inc.',49.37,0.02,0.04,'9/1 12:00am', 'Finance'],
  35. ['E.I. du Pont de Nemours and Company',40.48,0.51,1.28,'9/1 12:00am', 'Manufacturing'],
  36. ['Exxon Mobil Corp',68.1,-0.43,-0.64,'9/1 12:00am', 'Manufacturing'],
  37. ['General Electric Company',34.14,-0.08,-0.23,'9/1 12:00am', 'Manufacturing'],
  38. ['General Motors Corporation',30.27,1.09,3.74,'9/1 12:00am', 'Automotive'],
  39. ['Hewlett-Packard Co.',36.53,-0.03,-0.08,'9/1 12:00am', 'Computer'],
  40. ['Honeywell Intl Inc',38.77,0.05,0.13,'9/1 12:00am', 'Manufacturing'],
  41. ['Intel Corporation',19.88,0.31,1.58,'9/1 12:00am', 'Computer'],
  42. ['International Business Machines',81.41,0.44,0.54,'9/1 12:00am', 'Computer'],
  43. ['Johnson & Johnson',64.72,0.06,0.09,'9/1 12:00am', 'Medical'],
  44. ['JP Morgan & Chase & Co',45.73,0.07,0.15,'9/1 12:00am', 'Finance'],
  45. ['McDonald\'s Corporation',36.76,0.86,2.40,'9/1 12:00am', 'Food'],
  46. ['Merck & Co., Inc.',40.96,0.41,1.01,'9/1 12:00am', 'Medical'],
  47. ['Microsoft Corporation',25.84,0.14,0.54,'9/1 12:00am', 'Computer'],
  48. ['Pfizer Inc',27.96,0.4,1.45,'9/1 12:00am', 'Services', 'Medical'],
  49. ['The Coca-Cola Company',45.07,0.26,0.58,'9/1 12:00am', 'Food'],
  50. ['The Home Depot, Inc.',34.64,0.35,1.02,'9/1 12:00am', 'Retail'],
  51. ['The Procter & Gamble Company',61.91,0.01,0.02,'9/1 12:00am', 'Manufacturing'],
  52. ['United Technologies Corporation',63.26,0.55,0.88,'9/1 12:00am', 'Computer'],
  53. ['Verizon Communications',35.57,0.39,1.11,'9/1 12:00am', 'Services'],
  54. ['Wal-Mart Stores, Inc.',45.45,0.73,1.63,'9/1 12:00am', 'Retail'],
  55. ['Walt Disney Company (The) (Holding Company)',29.89,0.24,0.81,'9/1 12:00am', 'Services']
  56. ];
  57. // add in some dummy descriptions
  58. for(var i = 0; i < Ext.grid.dummyData.length; i++){
  59. Ext.grid.dummyData[i].push('Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Sed metus nibh, sodales a, porta at, vulputate eget, dui. Pellentesque ut nisl. ');
  60. }
  61. Ext.QuickTips.init();
  62. var getLocalStore = function() {
  63. return Ext.create('Ext.data.ArrayStore', {
  64. model: 'Company',
  65. data: Ext.grid.dummyData
  66. });
  67. };
  68. ////////////////////////////////////////////////////////////////////////////////////////
  69. // Grid 1
  70. ////////////////////////////////////////////////////////////////////////////////////////
  71. // row expander
  72. var grid1 = Ext.create('Ext.grid.Panel', {
  73. store: getLocalStore(),
  74. columns: [
  75. {text: "Company", flex: 1, dataIndex: 'company'},
  76. {text: "Price", renderer: Ext.util.Format.usMoney, dataIndex: 'price'},
  77. {text: "Change", dataIndex: 'change'},
  78. {text: "% Change", dataIndex: 'pctChange'},
  79. {text: "Last Updated", renderer: Ext.util.Format.dateRenderer('m/d/Y'), dataIndex: 'lastChange'}
  80. ],
  81. width: 600,
  82. height: 300,
  83. plugins: [{
  84. ptype: 'rowexpander',
  85. rowBodyTpl : [
  86. '<p><b>Company:</b> {company}</p><br>',
  87. '<p><b>Summary:</b> {desc}</p>'
  88. ]
  89. }],
  90. collapsible: true,
  91. animCollapse: false,
  92. title: 'Expander Rows in a Collapsible Grid',
  93. iconCls: 'icon-grid',
  94. renderTo: Ext.getBody()
  95. });
  96. ////////////////////////////////////////////////////////////////////////////////////////
  97. // Grid 2
  98. ////////////////////////////////////////////////////////////////////////////////////////
  99. var sm = Ext.create('Ext.selection.CheckboxModel');
  100. var grid2 = Ext.create('Ext.grid.Panel', {
  101. store: getLocalStore(),
  102. selModel: sm,
  103. columns: [
  104. {text: "Company", width: 200, dataIndex: 'company'},
  105. {text: "Price", renderer: Ext.util.Format.usMoney, dataIndex: 'price'},
  106. {text: "Change", dataIndex: 'change'},
  107. {text: "% Change", dataIndex: 'pctChange'},
  108. {text: "Last Updated", width: 135, renderer: Ext.util.Format.dateRenderer('m/d/Y'), dataIndex: 'lastChange'}
  109. ],
  110. columnLines: true,
  111. width: 600,
  112. height: 300,
  113. frame: true,
  114. title: 'Framed with Checkbox Selection and Horizontal Scrolling',
  115. iconCls: 'icon-grid',
  116. renderTo: Ext.getBody()
  117. });
  118. ////////////////////////////////////////////////////////////////////////////////////////
  119. // Grid 3
  120. ////////////////////////////////////////////////////////////////////////////////////////
  121. var grid3 = Ext.create('Ext.grid.Panel', {
  122. store: getLocalStore(),
  123. columns: [
  124. Ext.create('Ext.grid.RowNumberer'),
  125. {text: "Company", flex: 1, sortable: true, dataIndex: 'company'},
  126. {text: "Price", width: 120, sortable: true, renderer: Ext.util.Format.usMoney, dataIndex: 'price'},
  127. {text: "Change", width: 120, sortable: true, dataIndex: 'change'},
  128. {text: "% Change", width: 120, sortable: true, dataIndex: 'pctChange'},
  129. {text: "Last Updated", width: 120, sortable: true, renderer: Ext.util.Format.dateRenderer('m/d/Y'), dataIndex: 'lastChange'}
  130. ],
  131. columnLines: true,
  132. width:600,
  133. height:300,
  134. title:'Grid with Numbered Rows',
  135. iconCls:'icon-grid',
  136. renderTo: Ext.getBody()
  137. });
  138. ////////////////////////////////////////////////////////////////////////////////////////
  139. // Grid 4
  140. ////////////////////////////////////////////////////////////////////////////////////////
  141. var selModel = Ext.create('Ext.selection.CheckboxModel', {
  142. listeners: {
  143. selectionchange: function(sm, selections) {
  144. grid4.down('#removeButton').setDisabled(selections.length == 0);
  145. }
  146. }
  147. });
  148. var grid4 = Ext.create('Ext.grid.Panel', {
  149. id:'button-grid',
  150. store: getLocalStore(),
  151. columns: [
  152. {text: "Company", flex: 1, sortable: true, dataIndex: 'company'},
  153. {text: "Price", width: 120, sortable: true, renderer: Ext.util.Format.usMoney, dataIndex: 'price'},
  154. {text: "Change", width: 120, sortable: true, dataIndex: 'change'},
  155. {text: "% Change", width: 120, sortable: true, dataIndex: 'pctChange'},
  156. {text: "Last Updated", width: 120, sortable: true, renderer: Ext.util.Format.dateRenderer('m/d/Y'), dataIndex: 'lastChange'}
  157. ],
  158. columnLines: true,
  159. selModel: selModel,
  160. // inline buttons
  161. dockedItems: [{
  162. xtype: 'toolbar',
  163. dock: 'bottom',
  164. ui: 'footer',
  165. layout: {
  166. pack: 'center'
  167. },
  168. items: [{
  169. minWidth: 80,
  170. text: 'Save'
  171. },{
  172. minWidth: 80,
  173. text: 'Cancel'
  174. }]
  175. }, {
  176. xtype: 'toolbar',
  177. items: [{
  178. text:'Add Something',
  179. tooltip:'Add a new row',
  180. iconCls:'add'
  181. }, '-', {
  182. text:'Options',
  183. tooltip:'Set options',
  184. iconCls:'option'
  185. },'-',{
  186. itemId: 'removeButton',
  187. text:'Remove Something',
  188. tooltip:'Remove the selected item',
  189. iconCls:'remove',
  190. disabled: true
  191. }]
  192. }],
  193. width: 600,
  194. height: 300,
  195. frame: true,
  196. title: 'Support for standard Panel features such as framing, buttons and toolbars',
  197. iconCls: 'icon-grid',
  198. renderTo: Ext.getBody()
  199. });
  200. });