grid3.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390
  1. // Array data for the grids
  2. Ext.grid.dummyData = [
  3. ['3m Co', 71.72, 0.02, 0.03, '9/1 12:00am', 'Manufacturing', 1],
  4. ['Alcoa Inc', 29.01, 0.42, 1.47, '9/1 12:00am', 'Manufacturing', 2],
  5. ['Altria Group Inc', 83.81, 0.28, 0.34, '9/1 12:00am', 'Manufacturing',
  6. 3],
  7. ['American Express Company', 52.55, 0.01, 0.02, '9/1 12:00am',
  8. 'Finance', 4],
  9. ['American International Group, Inc.', 64.13, 0.31, 0.49,
  10. '9/1 12:00am', 'Services', 5],
  11. ['AT&T Inc.', 31.61, -0.48, -1.54, '9/1 12:00am', 'Services', 6],
  12. ['Boeing Co.', 75.43, 0.53, 0.71, '9/1 12:00am', 'Manufacturing', 7],
  13. ['Caterpillar Inc.', 67.27, 0.92, 1.39, '9/1 12:00am', 'Services', 8],
  14. ['Citigroup, Inc.', 49.37, 0.02, 0.04, '9/1 12:00am', 'Finance', 9],
  15. ['E.I. du Pont de Nemours and Company', 40.48, 0.51, 1.28,
  16. '9/1 12:00am', 'Manufacturing', 10],
  17. ['Exxon Mobil Corp', 68.1, -0.43, -0.64, '9/1 12:00am',
  18. 'Manufacturing', 11],
  19. ['General Electric Company', 34.14, -0.08, -0.23, '9/1 12:00am',
  20. 'Manufacturing', 12],
  21. ['General Motors Corporation', 30.27, 1.09, 3.74, '9/1 12:00am',
  22. 'Automotive', 13],
  23. ['Hewlett-Packard Co.', 36.53, -0.03, -0.08, '9/1 12:00am', 'Computer',
  24. 14],
  25. ['Honeywell Intl Inc', 38.77, 0.05, 0.13, '9/1 12:00am',
  26. 'Manufacturing', 15],
  27. ['Intel Corporation', 19.88, 0.31, 1.58, '9/1 12:00am', 'Computer', 16],
  28. ['International Business Machines', 81.41, 0.44, 0.54, '9/1 12:00am',
  29. 'Computer', 17],
  30. ['Johnson & Johnson', 64.72, 0.06, 0.09, '9/1 12:00am', 'Medical', 18],
  31. ['JP Morgan & Chase & Co', 45.73, 0.07, 0.15, '9/1 12:00am', 'Finance',
  32. 19],
  33. ['McDonald\'s Corporation', 36.76, 0.86, 2.40, '9/1 12:00am', 'Food',
  34. 22],
  35. ['Merck & Co., Inc.', 40.96, 0.41, 1.01, '9/1 12:00am', 'Medical', 21],
  36. ['Microsoft Corporation', 25.84, 0.14, 0.54, '9/1 12:00am', 'Computer',
  37. 24],
  38. ['Pfizer Inc', 27.96, 0.4, 1.45, '9/1 12:00am', 'Services', 'Medical',
  39. 25],
  40. ['The Coca-Cola Company', 45.07, 0.26, 0.58, '9/1 12:00am', 'Food', 26],
  41. ['The Home Depot, Inc.', 34.64, 0.35, 1.02, '9/1 12:00am', 'Retail', 27],
  42. ['The Procter & Gamble Company', 61.91, 0.01, 0.02, '9/1 12:00am',
  43. 'Manufacturing', 28],
  44. ['United Technologies Corporation', 63.26, 0.55, 0.88, '9/1 12:00am',
  45. 'Computer', 100],
  46. ['Verizon Communications', 35.57, 0.39, 1.11, '9/1 12:00am',
  47. 'Services', 56],
  48. ['Wal-Mart Stores, Inc.', 45.45, 0.73, 1.63, '9/1 12:00am', 'Retail',
  49. 45],
  50. ['Walt Disney Company (The) (Holding Company)', 29.89, 0.24, 0.81,
  51. '9/1 12:00am', 'Services', 78]];
  52. // add in some dummy descriptions
  53. for (var i = 0; i < Ext.grid.dummyData.length; i++) {
  54. Ext.grid.dummyData[i]
  55. .push('Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Sed metus nibh, sodales a, porta at, vulputate eget, dui. Pellentesque ut nisl. Maecenas tortor turpis, interdum non, sodales non, iaculis ac, lacus. Vestibulum auctor, tortor quis iaculis malesuada, libero lectus bibendum purus, sit amet tincidunt quam turpis vel lacus. In pellentesque nisl non sem. Suspendisse nunc sem, pretium eget, cursus a, fringilla vel, urna.<br/><br/>Aliquam commodo ullamcorper erat. Nullam vel justo in neque porttitor laoreet. Aenean lacus dui, consequat eu, adipiscing eget, nonummy non, nisi. Morbi nunc est, dignissim non, ornare sed, luctus eu, massa. Vivamus eget quam. Vivamus tincidunt diam nec urna. Curabitur velit.');
  56. }
  57. /*
  58. * Ext JS Library 2.0 Copyright(c) 2006-2007, Ext JS, LLC. licensing@extjs.com
  59. *
  60. * http://extjs.com/license
  61. */
  62. Ext.onReady(function() {
  63. Ext.QuickTips.init();
  64. var xg = Ext.grid;
  65. // shared reader
  66. var reader = new Ext.data.ArrayReader({}, [{
  67. name : 'company'
  68. }, {
  69. name : 'price',
  70. type : 'float'
  71. }, {
  72. name : 'change',
  73. type : 'float'
  74. }, {
  75. name : 'pctChange',
  76. type : 'float'
  77. }, {
  78. name : 'lastChange',
  79. type : 'date',
  80. dateFormat : 'n/j h:ia'
  81. }, {
  82. name : 'industry'
  83. }, {
  84. name : 'Id'
  85. }, {
  86. name : 'desc'
  87. }]);
  88. // //////////////////////////////////////////////////////////////////////////////////////
  89. // Grid 1
  90. // //////////////////////////////////////////////////////////////////////////////////////
  91. // row expander
  92. var expander = new xg.RowExpander({
  93. tpl : new Ext.Template('<p><b>Company:</b> {company}<br>',
  94. '<p><b>Summary:</b> {desc}</p>')
  95. });
  96. var grid1 = new xg.GridPanel({
  97. store : new Ext.data.Store({
  98. reader : reader,
  99. data : xg.dummyData
  100. }),
  101. cm : new xg.ColumnModel([
  102. expander, // ------------
  103. {
  104. id : 'Id',
  105. header : "Company",
  106. width : 40,
  107. sortable : true,
  108. dataIndex : 'company'
  109. }, {
  110. header : "Price",
  111. width : 20,
  112. sortable : true,
  113. renderer : Ext.util.Format.usMoney,
  114. dataIndex : 'price'
  115. }, {
  116. header : "Change",
  117. width : 20,
  118. sortable : true,
  119. dataIndex : 'change'
  120. }, {
  121. header : "% Change",
  122. width : 20,
  123. sortable : true,
  124. dataIndex : 'pctChange'
  125. }, {
  126. header : "Last Updated",
  127. width : 20,
  128. sortable : true,
  129. renderer : Ext.util.Format.dateRenderer('m/d/Y'),
  130. dataIndex : 'lastChange'
  131. }]),
  132. viewConfig : {
  133. // forceFit:false
  134. forceFit : true
  135. },
  136. // loadMask: {msg:'data is loading pls wait up'},
  137. width : 600,
  138. height : 300,
  139. plugins : expander, // -------
  140. collapsible : true,
  141. animCollapse : false,
  142. title : 'Grid 1 - Expander Rows, Collapse and Force Fit',
  143. iconCls : 'icon-grid',
  144. renderTo : document.body
  145. });
  146. grid1.addListener("rowcontextmenu", rightClickFn);
  147. grid1.selectRowindex = "";
  148. var rightClick = new Ext.menu.Menu({
  149. id : "rightClickCont",
  150. items : [{
  151. id : "rMenu1",
  152. handler : rMenu1Fn,
  153. text : "menu1"
  154. }, {
  155. // id: "rMenu2",
  156. // handler: rMenu2Fn,
  157. text : "menu2"
  158. }]
  159. });
  160. function rightClickFn(grid1, rowindex, e) {
  161. e.preventDefault();
  162. grid1.selectRowindex = rowindex;
  163. rightClick.showAt(e.getXY());
  164. }
  165. function rMenu1Fn() {
  166. var record = grid1.getStore().getAt(grid1.selectRowindex); // Get the
  167. // Record
  168. var fieldName = grid1.getColumnModel().getDataIndex(1); // Get field
  169. // name
  170. var data = record.get(fieldName);
  171. Ext.MessageBox.alert("right", record.data["Id"] + "[fieldName:"
  172. + fieldName + "] = " + data + "grid1.selectRowindex = "
  173. + grid1.selectRowindex);
  174. }
  175. // //////////////////////////////////////////////////////////////////////////////////////
  176. // Grid 2
  177. // //////////////////////////////////////////////////////////////////////////////////////
  178. var sm = new xg.CheckboxSelectionModel();
  179. sm.handleMouseDown = Ext.emptyFn;
  180. var grid2 = new xg.GridPanel({
  181. store : new Ext.data.Store({
  182. reader : reader,
  183. data : xg.dummyData
  184. }),
  185. cm : new xg.ColumnModel([sm, {
  186. id : 'company',
  187. header : "Company",
  188. width : 200,
  189. sortable : true,
  190. dataIndex : 'company'
  191. }, {
  192. header : "Price",
  193. width : 120,
  194. sortable : true,
  195. renderer : Ext.util.Format.usMoney,
  196. dataIndex : 'price'
  197. }, {
  198. header : "Change",
  199. width : 120,
  200. sortable : true,
  201. dataIndex : 'change'
  202. }, {
  203. header : "% Change",
  204. width : 120,
  205. sortable : true,
  206. dataIndex : 'pctChange'
  207. }, {
  208. header : "Last Updated",
  209. width : 135,
  210. sortable : true,
  211. renderer : Ext.util.Format.dateRenderer('m/d/Y'),
  212. dataIndex : 'lastChange'
  213. }]),
  214. sm : sm,
  215. width : 600,
  216. height : 300,
  217. frame : true,
  218. title : 'Grid 2 - Framed with Checkbox Selection and Horizontal Scrolling',
  219. iconCls : 'icon-grid',
  220. renderTo : document.body
  221. });
  222. // -------------------------------------------
  223. grid2.on('rowclick', function(grid2, rowindex) {
  224. alert(rowindex)
  225. if (sm.isSelected(rowindex))
  226. sm.deselectRow(rowindex);
  227. else
  228. sm.selectRow(rowindex, true);
  229. });
  230. // //////////////////////////////////////////////////////////////////////////////////////
  231. // Grid 3
  232. // //////////////////////////////////////////////////////////////////////////////////////
  233. var grid3 = new xg.GridPanel({
  234. store : new Ext.data.Store({
  235. reader : reader,
  236. data : xg.dummyData
  237. }),
  238. cm : new xg.ColumnModel([new xg.RowNumberer(), {
  239. id : 'company',
  240. header : "Company",
  241. width : 40,
  242. sortable : true,
  243. dataIndex : 'company'
  244. }, {
  245. header : "Price",
  246. width : 20,
  247. sortable : true,
  248. renderer : Ext.util.Format.usMoney,
  249. dataIndex : 'price'
  250. }, {
  251. header : "Change",
  252. width : 20,
  253. sortable : true,
  254. dataIndex : 'change'
  255. }, {
  256. header : "% Change",
  257. width : 20,
  258. sortable : true,
  259. dataIndex : 'pctChange'
  260. }, {
  261. header : "Last Updated",
  262. width : 20,
  263. sortable : true,
  264. renderer : Ext.util.Format.dateRenderer('m/d/Y'),
  265. dataIndex : 'lastChange'
  266. }]),
  267. viewConfig : {
  268. forceFit : true
  269. },
  270. width : 600,
  271. height : 300,
  272. title : 'Grid 3 - Grid with Numbered Rows and Force Fit',
  273. iconCls : 'icon-grid',
  274. renderTo : document.body
  275. });
  276. // //////////////////////////////////////////////////////////////////////////////////////
  277. // Grid 4
  278. // //////////////////////////////////////////////////////////////////////////////////////
  279. var sm2 = new xg.CheckboxSelectionModel();
  280. // var sm2 = new xg.CheckboxSelectionModel({singleSelect:true});
  281. var grid4 = new xg.GridPanel({
  282. id : 'button-grid',
  283. store : new Ext.data.Store({
  284. reader : reader,
  285. data : xg.dummyData
  286. }),
  287. cm : new xg.ColumnModel([sm, {
  288. id : 'company',
  289. header : "Company",
  290. width : 40,
  291. sortable : true,
  292. dataIndex : 'company'
  293. }, {
  294. header : "Price",
  295. width : 20,
  296. sortable : true,
  297. renderer : Ext.util.Format.usMoney,
  298. dataIndex : 'price'
  299. }, {
  300. header : "Change",
  301. width : 20,
  302. sortable : true,
  303. dataIndex : 'change'
  304. }, {
  305. header : "% Change",
  306. width : 20,
  307. sortable : true,
  308. dataIndex : 'pctChange'
  309. }, {
  310. header : "Last Updated",
  311. width : 20,
  312. sortable : true,
  313. renderer : Ext.util.Format.dateRenderer('m/d/Y'),
  314. dataIndex : 'lastChange'
  315. }]),
  316. sm : sm2,
  317. viewConfig : {
  318. forceFit : true
  319. },
  320. // inline buttons
  321. buttons : [{
  322. text : 'Save'
  323. }, {
  324. text : 'Cancel'
  325. }],
  326. buttonAlign : 'center',
  327. // inline toolbars
  328. tbar : [{
  329. text : 'Add Something',
  330. tooltip : 'Add a new row',
  331. iconCls : 'add',
  332. handler : function() {
  333. alert("You clicked Button Add Something");
  334. }
  335. }, '-', {
  336. text : 'Options',
  337. tooltip : 'Blah blah blah blaht',
  338. iconCls : 'option',
  339. handler : function() {
  340. alert("You clicked Button Options");
  341. }
  342. }, '-', {
  343. text : 'Remove Something',
  344. tooltip : 'Remove the selected item',
  345. iconCls : 'remove',
  346. handler : function() {
  347. var s = grid4.getSelections();
  348. for (var i = 0, len = s.length; i < len; i++) {
  349. var r = s[i];
  350. alert(r.data["Id"] + r.data["company"]);
  351. }
  352. alert("You clicked Button Remove Something");
  353. }
  354. }],
  355. // -------------------------------------------
  356. width : 600,
  357. height : 300,
  358. frame : true,
  359. title : 'Grid 4 - Support for standard Panel features such as framing, buttons and toolbars',
  360. iconCls : 'icon-grid',
  361. renderTo : document.body
  362. });
  363. });