b0c9a26e108a189de27520bc52dc128bbd6be0ee.svn-base 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  1. /*
  2. * Ext JS Library 2.0 Copyright(c) 2006-2007, Ext JS, LLC. licensing@extjs.com
  3. *
  4. * http://extjs.com/license
  5. */
  6. Ext.grid.GroupingView = Ext.extend(Ext.grid.GridView, {
  7. hideGroupedColumn : false,
  8. showGroupName : true,
  9. startCollapsed : false,
  10. enableGrouping : true,
  11. enableGroupingMenu : true,
  12. enableNoGroups : true,
  13. emptyGroupText : "(None)",
  14. ignoreAdd : false,
  15. groupTextTpl : "{text}",
  16. gidSeed : 1000,
  17. initTemplates : function() {
  18. Ext.grid.GroupingView.superclass.initTemplates.call(this);
  19. this.state = {};
  20. var A = this.grid.getSelectionModel();
  21. A.on(A.selectRow ? "beforerowselect" : "beforecellselect",
  22. this.onBeforeRowSelect, this);
  23. if (!this.startGroup) {
  24. this.startGroup = new Ext.XTemplate(
  25. "<div id=\"{groupId}\" class=\"x-grid-group {cls}\">",
  26. "<div id=\"{groupId}-hd\" class=\"x-grid-group-hd\" style=\"{style}\"><div>",
  27. this.groupTextTpl, "</div></div>",
  28. "<div id=\"{groupId}-bd\" class=\"x-grid-group-body\">")
  29. }
  30. this.startGroup.compile();
  31. this.endGroup = "</div></div>"
  32. },
  33. findGroup : function(A) {
  34. return Ext.fly(A).up(".x-grid-group", this.mainBody.dom)
  35. },
  36. getGroups : function() {
  37. return this.hasRows() ? this.mainBody.dom.childNodes : []
  38. },
  39. onAdd : function() {
  40. if (this.enableGrouping && !this.ignoreAdd) {
  41. var A = this.getScrollState();
  42. this.refresh();
  43. this.restoreScroll(A)
  44. } else {
  45. if (!this.enableGrouping) {
  46. Ext.grid.GroupingView.superclass.onAdd.apply(this, arguments)
  47. }
  48. }
  49. },
  50. onRemove : function(E, A, B, D) {
  51. Ext.grid.GroupingView.superclass.onRemove.apply(this, arguments);
  52. var C = document.getElementById(A._groupId);
  53. if (C && C.childNodes[1].childNodes.length < 1) {
  54. Ext.removeNode(C)
  55. }
  56. this.applyEmptyText()
  57. },
  58. refreshRow : function(A) {
  59. if (this.ds.getCount() == 1) {
  60. this.refresh()
  61. } else {
  62. this.isUpdating = true;
  63. Ext.grid.GroupingView.superclass.refreshRow.apply(this, arguments);
  64. this.isUpdating = false
  65. }
  66. },
  67. beforeMenuShow : function() {
  68. var C = this.getGroupField();
  69. var B = this.hmenu.items.get("groupBy");
  70. if (B) {
  71. B.setDisabled(this.cm.config[this.hdCtxIndex].groupable === false)
  72. }
  73. var A = this.hmenu.items.get("showGroups");
  74. if (A) {
  75. A.setChecked(!!C)
  76. }
  77. },
  78. renderUI : function() {
  79. Ext.grid.GroupingView.superclass.renderUI.call(this);
  80. this.mainBody.on("mousedown", this.interceptMouse, this);
  81. if (this.enableGroupingMenu && this.hmenu) {
  82. this.hmenu.add("-", {
  83. id : "groupBy",
  84. text : this.groupByText,
  85. handler : this.onGroupByClick,
  86. scope : this,
  87. iconCls : "x-group-by-icon"
  88. });
  89. if (this.enableNoGroups) {
  90. this.hmenu.add({
  91. id : "showGroups",
  92. text : this.showGroupsText,
  93. checked : true,
  94. checkHandler : this.onShowGroupsClick,
  95. scope : this
  96. })
  97. }
  98. this.hmenu.on("beforeshow", this.beforeMenuShow, this)
  99. }
  100. },
  101. onGroupByClick : function() {
  102. this.grid.store.groupBy(this.cm.getDataIndex(this.hdCtxIndex))
  103. },
  104. onShowGroupsClick : function(A, B) {
  105. if (B) {
  106. this.onGroupByClick()
  107. } else {
  108. this.grid.store.clearGrouping()
  109. }
  110. },
  111. toggleGroup : function(C, B) {
  112. this.grid.stopEditing();
  113. C = Ext.getDom(C);
  114. var A = Ext.fly(C);
  115. B = B !== undefined ? B : A.hasClass("x-grid-group-collapsed");
  116. this.state[A.dom.id] = B;
  117. A[B ? "removeClass" : "addClass"]("x-grid-group-collapsed")
  118. },
  119. toggleAllGroups : function(C) {
  120. var B = this.getGroups();
  121. for (var D = 0, A = B.length; D < A; D++) {
  122. this.toggleGroup(B[D], C)
  123. }
  124. },
  125. expandAllGroups : function() {
  126. this.toggleAllGroups(true)
  127. },
  128. collapseAllGroups : function() {
  129. this.toggleAllGroups(false)
  130. },
  131. interceptMouse : function(B) {
  132. var A = B.getTarget(".x-grid-group-hd", this.mainBody);
  133. if (A) {
  134. B.stopEvent();
  135. this.toggleGroup(A.parentNode)
  136. }
  137. },
  138. getGroup : function(A, D, F, G, B, E) {
  139. var C = F ? F(A, {}, D, G, B, E) : String(A);
  140. if (C === "") {
  141. C = this.cm.config[B].emptyGroupText || this.emptyGroupText
  142. }
  143. return C
  144. },
  145. getGroupField : function() {
  146. return this.grid.store.getGroupState()
  147. },
  148. renderRows : function() {
  149. var A = this.getGroupField();
  150. var D = !!A;
  151. if (this.hideGroupedColumn) {
  152. var B = this.cm.findColumnIndex(A);
  153. if (!D && this.lastGroupField !== undefined) {
  154. this.mainBody.update("");
  155. this.cm.setHidden(this.cm.findColumnIndex(this.lastGroupField),
  156. false);
  157. delete this.lastGroupField
  158. } else {
  159. if (D && this.lastGroupField === undefined) {
  160. this.lastGroupField = A;
  161. this.cm.setHidden(B, true)
  162. } else {
  163. if (D && this.lastGroupField !== undefined
  164. && A !== this.lastGroupField) {
  165. this.mainBody.update("");
  166. var C = this.cm.findColumnIndex(this.lastGroupField);
  167. this.cm.setHidden(C, false);
  168. this.lastGroupField = A;
  169. this.cm.setHidden(B, true)
  170. }
  171. }
  172. }
  173. }
  174. return Ext.grid.GroupingView.superclass.renderRows.apply(this,
  175. arguments)
  176. },
  177. doRender : function(D, G, P, A, O, R) {
  178. if (G.length < 1) {
  179. return ""
  180. }
  181. var Y = this.getGroupField();
  182. var N = this.cm.findColumnIndex(Y);
  183. this.enableGrouping = !!Y;
  184. if (!this.enableGrouping || this.isUpdating) {
  185. return Ext.grid.GroupingView.superclass.doRender.apply(this,
  186. arguments)
  187. }
  188. var H = "width:" + this.getTotalWidth() + ";";
  189. var Q = this.grid.getGridEl().id;
  190. var F = this.cm.config[N];
  191. var B = F.groupRenderer || F.renderer;
  192. var C = this.startCollapsed ? "x-grid-group-collapsed" : "";
  193. var S = this.showGroupName ? (F.groupName || F.header) + ": " : "";
  194. var X = [], K, T, U, M;
  195. for (T = 0, U = G.length; T < U; T++) {
  196. var J = A + T;
  197. var L = G[T], E = L.data[Y], V = this.getGroup(E, L, B, J, N, P);
  198. if (!K || K.group != V) {
  199. M = Q + "-gp-" + Y + "-" + V;
  200. var I = C ? C : (this.state[M] === false
  201. ? "x-grid-group-collapsed"
  202. : "");
  203. K = {
  204. group : V,
  205. gvalue : E,
  206. text : S + V,
  207. groupId : M,
  208. startRow : J,
  209. rs : [L],
  210. cls : I,
  211. style : H
  212. };
  213. X.push(K)
  214. } else {
  215. K.rs.push(L)
  216. }
  217. L._groupId = M
  218. }
  219. var W = [];
  220. for (T = 0, U = X.length; T < U; T++) {
  221. var V = X[T];
  222. this.doGroupStart(W, V, D, P, O);
  223. W[W.length] = Ext.grid.GroupingView.superclass.doRender.call(this,
  224. D, V.rs, P, V.startRow, O, R);
  225. this.doGroupEnd(W, V, D, P, O)
  226. }
  227. return W.join("")
  228. },
  229. getGroupId : function(F) {
  230. var D = this.grid.getGridEl().id;
  231. var C = this.getGroupField();
  232. var E = this.cm.findColumnIndex(C);
  233. var B = this.cm.config[E];
  234. var G = B.groupRenderer || B.renderer;
  235. var A = this.getGroup(F, {
  236. data : {}
  237. }, G, 0, E, this.ds);
  238. return D + "-gp-" + C + "-" + F
  239. },
  240. doGroupStart : function(A, D, B, E, C) {
  241. A[A.length] = this.startGroup.apply(D)
  242. },
  243. doGroupEnd : function(A, D, B, E, C) {
  244. A[A.length] = this.endGroup
  245. },
  246. getRows : function() {
  247. if (!this.enableGrouping) {
  248. return Ext.grid.GroupingView.superclass.getRows.call(this)
  249. }
  250. var G = [];
  251. var F, C = this.getGroups();
  252. for (var E = 0, A = C.length; E < A; E++) {
  253. F = C[E].childNodes[1].childNodes;
  254. for (var D = 0, B = F.length; D < B; D++) {
  255. G[G.length] = F[D]
  256. }
  257. }
  258. return G
  259. },
  260. updateGroupWidths : function() {
  261. if (!this.enableGrouping || !this.hasRows()) {
  262. return
  263. }
  264. var C = Math.max(this.cm.getTotalWidth(), this.el.dom.offsetWidth
  265. - this.scrollOffset)
  266. + "px";
  267. var B = this.getGroups();
  268. for (var D = 0, A = B.length; D < A; D++) {
  269. B[D].firstChild.style.width = C
  270. }
  271. },
  272. onColumnWidthUpdated : function(C, A, B) {
  273. this.updateGroupWidths()
  274. },
  275. onAllColumnWidthsUpdated : function(A, B) {
  276. this.updateGroupWidths()
  277. },
  278. onColumnHiddenUpdated : function(B, C, A) {
  279. this.updateGroupWidths()
  280. },
  281. onLayout : function() {
  282. this.updateGroupWidths()
  283. },
  284. onBeforeRowSelect : function(D, C) {
  285. if (!this.enableGrouping) {
  286. return
  287. }
  288. var B = this.getRow(C);
  289. if (B && !B.offsetParent) {
  290. var A = this.findGroup(B);
  291. this.toggleGroup(A, true)
  292. }
  293. },
  294. groupByText : "Group By This Field",
  295. showGroupsText : "Show in Groups"
  296. });
  297. Ext.grid.GroupingView.GROUP_ID = 1000;