You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

144 lines
4.7 KiB

2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /*
  2. This file is part of Ext JS 3.4
  3. Copyright (c) 2011-2013 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
  7. published by the Free Software Foundation and appearing in the file LICENSE included in the
  8. packaging of this file.
  9. Please review the following information to ensure the GNU General Public License version 3.0
  10. requirements will be met: http://www.gnu.org/copyleft/gpl.html.
  11. If you are unsure which license is appropriate for your use, please contact the sales department
  12. at http://www.sencha.com/contact.
  13. Build date: 2013-04-03 15:07:25
  14. */
  15. Ext.onReady(function() {
  16. var structure = {
  17. Asia: ['Beijing', 'Tokyo'],
  18. Europe: ['Berlin', 'London', 'Paris']
  19. },
  20. products = ['ProductX', 'ProductY'],
  21. fields = [],
  22. columns = [],
  23. data = [],
  24. continentGroupRow = [],
  25. cityGroupRow = [];
  26. /*
  27. * Example method that generates:
  28. * 1) The column configuration for the grid
  29. * 2) The column grouping configuration
  30. * 3) The data for the store
  31. * 4) The fields for the store
  32. */
  33. function generateConfig(){
  34. var arr,
  35. numProducts = products.length;
  36. Ext.iterate(structure, function(continent, cities){
  37. continentGroupRow.push({
  38. header: continent,
  39. align: 'center',
  40. colspan: cities.length * numProducts
  41. });
  42. Ext.each(cities, function(city){
  43. cityGroupRow.push({
  44. header: city,
  45. colspan: numProducts,
  46. align: 'center'
  47. });
  48. Ext.each(products, function(product){
  49. fields.push({
  50. type: 'int',
  51. name: city + product
  52. });
  53. columns.push({
  54. dataIndex: city + product,
  55. header: product,
  56. renderer: Ext.util.Format.usMoney
  57. });
  58. });
  59. arr = [];
  60. for(var i = 0; i < 20; ++i){
  61. arr.push((Math.floor(Math.random()*11) + 1) * 100000);
  62. }
  63. data.push(arr);
  64. });
  65. })
  66. }
  67. // Run method to generate columns, fields, row grouping
  68. generateConfig();
  69. /*
  70. * continentGroupRow at this point is:
  71. * [
  72. * {header: 'Asia', colspan: 4, align: 'center'},
  73. * {header: 'Europe', colspan: 6, align: 'center'}
  74. * ]
  75. *
  76. * cityGroupRow at this point is:
  77. * [
  78. * {header: 'Beijing', colspan: 2, align: 'center'},
  79. * {header: 'Tokyo', colspan: 2, align: 'center'},
  80. * {header: 'Berlin', colspan: 2, align: 'center'},
  81. * {header: 'London', colspan: 2, align: 'center'},
  82. * {header: 'Paris', colspan: 2, align: 'center'}
  83. * ]
  84. */
  85. var group = new Ext.ux.grid.ColumnHeaderGroup({
  86. rows: [continentGroupRow, cityGroupRow]
  87. });
  88. /*
  89. * fields at this point is:
  90. * [
  91. * {type: 'int', name: 'BeijingProductX'},
  92. * {type: 'int', name: 'BeijingProductY'},
  93. * {type: 'int', name: 'TokyoProductX'},
  94. * {type: 'int', name: 'TokyoProductY'},
  95. * {type: 'int', name: 'BerlinProductX'},
  96. * {type: 'int', name: 'BerlinProductY'},
  97. * {type: 'int', name: 'LondonProductX'},
  98. * {type: 'int', name: 'LondonProductY'},
  99. * {type: 'int', name: 'ParisProductX'},
  100. * {type: 'int', name: 'ParisProductY'}
  101. * ]
  102. *
  103. * columns at this point is:
  104. * [
  105. * {dataIndex: 'BeijingProductX', header: 'ProductX'},
  106. * {dataIndex: 'BeijingProductY', header: 'ProductY'},
  107. * {dataIndex: 'TokyoProductX', header: 'ProductX'},
  108. * {dataIndex: 'TokyoProductY', header: 'ProductY'},
  109. * {dataIndex: 'BerlinProductX', header: 'ProductX'},
  110. * {dataIndex: 'BerlinProductY', header: 'ProductY'},
  111. * {dataIndex: 'LondonProductX', header: 'ProductX'},
  112. * {dataIndex: 'LondonProductY', header: 'ProductY'},
  113. * {dataIndex: 'ParisProductX', header: 'ProductX'},
  114. * {dataIndex: 'ParisProductY', header: 'ProductY'}
  115. * ]
  116. */
  117. var grid = new Ext.grid.GridPanel({
  118. renderTo: 'column-group-grid',
  119. title: 'Sales By Location',
  120. width: 1000,
  121. height: 400,
  122. store: new Ext.data.ArrayStore({
  123. fields: fields,
  124. data: data
  125. }),
  126. columns: columns,
  127. viewConfig: {
  128. forceFit: true
  129. },
  130. plugins: group
  131. });
  132. });