/ext-4.0.7/examples/grid/grid-plugins.js

https://bitbucket.org/srogerf/javascript · JavaScript · 230 lines · 184 code · 16 blank · 30 comment · 3 complexity · 368477a5d35221c18e05efb79e7d6785 MD5 · raw file

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