03e2dc929e09a4cfa6cde9e3e4d3d33529ae9e94.svn-base 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  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.ColumnModel = function(A) {
  7. this.setConfig(A, true);
  8. this.defaultWidth = 100;
  9. this.defaultSortable = false;
  10. this.addEvents("widthchange", "headerchange", "hiddenchange",
  11. "columnmoved", "columnlockchange", "configchange");
  12. Ext.grid.ColumnModel.superclass.constructor.call(this)
  13. };
  14. Ext.extend(Ext.grid.ColumnModel, Ext.util.Observable, {
  15. getColumnId : function(A) {
  16. return this.config[A].id
  17. },
  18. setConfig : function(C, B) {
  19. if (!B) {
  20. delete this.totalWidth;
  21. for (var D = 0, A = this.config.length; D < A; D++) {
  22. var E = this.config[D];
  23. if (E.editor) {
  24. E.editor.destroy()
  25. }
  26. }
  27. }
  28. this.config = C;
  29. this.lookup = {};
  30. for (var D = 0, A = C.length; D < A; D++) {
  31. var E = C[D];
  32. if (typeof E.renderer == "string") {
  33. E.renderer = Ext.util.Format[E.renderer]
  34. }
  35. if (typeof E.id == "undefined") {
  36. E.id = D
  37. }
  38. if (E.editor && E.editor.isFormField) {
  39. E.editor = new Ext.grid.GridEditor(E.editor)
  40. }
  41. this.lookup[E.id] = E
  42. }
  43. if (!B) {
  44. this.fireEvent("configchange", this)
  45. }
  46. },
  47. getColumnById : function(A) {
  48. return this.lookup[A]
  49. },
  50. getIndexById : function(C) {
  51. for (var B = 0, A = this.config.length; B < A; B++) {
  52. if (this.config[B].id == C) {
  53. return B
  54. }
  55. }
  56. return -1
  57. },
  58. moveColumn : function(C, A) {
  59. var B = this.config[C];
  60. this.config.splice(C, 1);
  61. this.config.splice(A, 0, B);
  62. this.dataMap = null;
  63. this.fireEvent("columnmoved", this, C, A)
  64. },
  65. isLocked : function(A) {
  66. return this.config[A].locked === true
  67. },
  68. setLocked : function(B, C, A) {
  69. if (this.isLocked(B) == C) {
  70. return
  71. }
  72. this.config[B].locked = C;
  73. if (!A) {
  74. this.fireEvent("columnlockchange", this, B, C)
  75. }
  76. },
  77. getTotalLockedWidth : function() {
  78. var A = 0;
  79. for (var B = 0; B < this.config.length; B++) {
  80. if (this.isLocked(B) && !this.isHidden(B)) {
  81. this.totalWidth += this.getColumnWidth(B)
  82. }
  83. }
  84. return A
  85. },
  86. getLockedCount : function() {
  87. for (var B = 0, A = this.config.length; B < A; B++) {
  88. if (!this.isLocked(B)) {
  89. return B
  90. }
  91. }
  92. },
  93. getColumnCount : function(C) {
  94. if (C === true) {
  95. var D = 0;
  96. for (var B = 0, A = this.config.length; B < A; B++) {
  97. if (!this.isHidden(B)) {
  98. D++
  99. }
  100. }
  101. return D
  102. }
  103. return this.config.length
  104. },
  105. getColumnsBy : function(D, C) {
  106. var E = [];
  107. for (var B = 0, A = this.config.length; B < A; B++) {
  108. var F = this.config[B];
  109. if (D.call(C || this, F, B) === true) {
  110. E[E.length] = F
  111. }
  112. }
  113. return E
  114. },
  115. isSortable : function(A) {
  116. if (typeof this.config[A].sortable == "undefined") {
  117. return this.defaultSortable
  118. }
  119. return this.config[A].sortable
  120. },
  121. getRenderer : function(A) {
  122. if (!this.config[A].renderer) {
  123. return Ext.grid.ColumnModel.defaultRenderer
  124. }
  125. return this.config[A].renderer
  126. },
  127. setRenderer : function(A, B) {
  128. this.config[A].renderer = B
  129. },
  130. getColumnWidth : function(A) {
  131. return this.config[A].width || this.defaultWidth
  132. },
  133. setColumnWidth : function(B, C, A) {
  134. this.config[B].width = C;
  135. this.totalWidth = null;
  136. if (!A) {
  137. this.fireEvent("widthchange", this, B, C)
  138. }
  139. },
  140. getTotalWidth : function(B) {
  141. if (!this.totalWidth) {
  142. this.totalWidth = 0;
  143. for (var C = 0, A = this.config.length; C < A; C++) {
  144. if (B || !this.isHidden(C)) {
  145. this.totalWidth += this.getColumnWidth(C)
  146. }
  147. }
  148. }
  149. return this.totalWidth
  150. },
  151. getColumnHeader : function(A) {
  152. return this.config[A].header
  153. },
  154. setColumnHeader : function(A, B) {
  155. this.config[A].header = B;
  156. this.fireEvent("headerchange", this, A, B)
  157. },
  158. getColumnTooltip : function(A) {
  159. return this.config[A].tooltip
  160. },
  161. setColumnTooltip : function(A, B) {
  162. this.config[A].tooltip = B
  163. },
  164. getDataIndex : function(A) {
  165. return this.config[A].dataIndex
  166. },
  167. setDataIndex : function(A, B) {
  168. this.config[A].dataIndex = B
  169. },
  170. findColumnIndex : function(C) {
  171. var D = this.config;
  172. for (var B = 0, A = D.length; B < A; B++) {
  173. if (D[B].dataIndex == C) {
  174. return B
  175. }
  176. }
  177. return -1
  178. },
  179. isCellEditable : function(A, B) {
  180. return (this.config[A].editable || (typeof this.config[A].editable == "undefined" && this.config[A].editor))
  181. ? true
  182. : false
  183. },
  184. getCellEditor : function(A, B) {
  185. return this.config[A].editor
  186. },
  187. setEditable : function(A, B) {
  188. this.config[A].editable = B
  189. },
  190. isHidden : function(A) {
  191. return this.config[A].hidden
  192. },
  193. isFixed : function(A) {
  194. return this.config[A].fixed
  195. },
  196. isResizable : function(A) {
  197. return A >= 0 && this.config[A].resizable !== false
  198. && this.config[A].fixed !== true
  199. },
  200. setHidden : function(A, B) {
  201. var C = this.config[A];
  202. if (C.hidden !== B) {
  203. C.hidden = B;
  204. this.totalWidth = null;
  205. this.fireEvent("hiddenchange", this, A, B)
  206. }
  207. },
  208. setEditor : function(A, B) {
  209. this.config[A].editor = B
  210. }
  211. });
  212. Ext.grid.ColumnModel.defaultRenderer = function(A) {
  213. if (typeof A == "string" && A.length < 1) {
  214. return "&#160;"
  215. }
  216. return A
  217. };
  218. Ext.grid.DefaultColumnModel = Ext.grid.ColumnModel;