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.

668 lines
28 KiB

2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. <title>The source code</title>
  6. <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
  7. <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
  8. <style type="text/css">
  9. .highlight { display: block; background-color: #ddd; }
  10. </style>
  11. <script type="text/javascript">
  12. function highlight() {
  13. document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
  14. }
  15. </script>
  16. </head>
  17. <body onload="prettyPrint(); highlight();">
  18. <pre class="prettyprint lang-js"><span id='Ext-grid-ColumnModel-method-constructor'><span id='Ext-grid-ColumnModel'>/**
  19. </span></span> * @class Ext.grid.ColumnModel
  20. * @extends Ext.util.Observable
  21. * &lt;p&gt;After the data has been read into the client side cache (&lt;b&gt;{@link Ext.data.Store Store}&lt;/b&gt;),
  22. * the ColumnModel is used to configure how and what parts of that data will be displayed in the
  23. * vertical slices (columns) of the grid. The Ext.grid.ColumnModel Class is the default implementation
  24. * of a ColumnModel used by implentations of {@link Ext.grid.GridPanel GridPanel}.&lt;/p&gt;
  25. * &lt;p&gt;Data is mapped into the store's records and then indexed into the ColumnModel using the
  26. * &lt;tt&gt;{@link Ext.grid.Column#dataIndex dataIndex}&lt;/tt&gt;:&lt;/p&gt;
  27. * &lt;pre&gt;&lt;code&gt;
  28. {data source} == mapping ==&gt; {data store} == &lt;b&gt;&lt;tt&gt;{@link Ext.grid.Column#dataIndex dataIndex}&lt;/tt&gt;&lt;/b&gt; ==&gt; {ColumnModel}
  29. * &lt;/code&gt;&lt;/pre&gt;
  30. * &lt;p&gt;Each {@link Ext.grid.Column Column} in the grid's ColumnModel is configured with a
  31. * &lt;tt&gt;{@link Ext.grid.Column#dataIndex dataIndex}&lt;/tt&gt; to specify how the data within
  32. * each record in the store is indexed into the ColumnModel.&lt;/p&gt;
  33. * &lt;p&gt;There are two ways to initialize the ColumnModel class:&lt;/p&gt;
  34. * &lt;p&gt;&lt;u&gt;Initialization Method 1: an Array&lt;/u&gt;&lt;/p&gt;
  35. &lt;pre&gt;&lt;code&gt;
  36. var colModel = new Ext.grid.ColumnModel([
  37. { header: &quot;Ticker&quot;, width: 60, sortable: true},
  38. { header: &quot;Company Name&quot;, width: 150, sortable: true, id: 'company'},
  39. { header: &quot;Market Cap.&quot;, width: 100, sortable: true},
  40. { header: &quot;$ Sales&quot;, width: 100, sortable: true, renderer: money},
  41. { header: &quot;Employees&quot;, width: 100, sortable: true, resizable: false}
  42. ]);
  43. &lt;/code&gt;&lt;/pre&gt;
  44. * &lt;p&gt;The ColumnModel may be initialized with an Array of {@link Ext.grid.Column} column configuration
  45. * objects to define the initial layout / display of the columns in the Grid. The order of each
  46. * {@link Ext.grid.Column} column configuration object within the specified Array defines the initial
  47. * order of the column display. A Column's display may be initially hidden using the
  48. * &lt;tt&gt;{@link Ext.grid.Column#hidden hidden}&lt;/tt&gt;&lt;/b&gt; config property (and then shown using the column
  49. * header menu). Fields that are not included in the ColumnModel will not be displayable at all.&lt;/p&gt;
  50. * &lt;p&gt;How each column in the grid correlates (maps) to the {@link Ext.data.Record} field in the
  51. * {@link Ext.data.Store Store} the column draws its data from is configured through the
  52. * &lt;b&gt;&lt;tt&gt;{@link Ext.grid.Column#dataIndex dataIndex}&lt;/tt&gt;&lt;/b&gt;. If the
  53. * &lt;b&gt;&lt;tt&gt;{@link Ext.grid.Column#dataIndex dataIndex}&lt;/tt&gt;&lt;/b&gt; is not explicitly defined (as shown in the
  54. * example above) it will use the column configuration's index in the Array as the index.&lt;/p&gt;
  55. * &lt;p&gt;See &lt;b&gt;&lt;tt&gt;{@link Ext.grid.Column}&lt;/tt&gt;&lt;/b&gt; for additional configuration options for each column.&lt;/p&gt;
  56. * &lt;p&gt;&lt;u&gt;Initialization Method 2: an Object&lt;/u&gt;&lt;/p&gt;
  57. * &lt;p&gt;In order to use configuration options from &lt;tt&gt;Ext.grid.ColumnModel&lt;/tt&gt;, an Object may be used to
  58. * initialize the ColumnModel. The column configuration Array will be specified in the &lt;tt&gt;&lt;b&gt;{@link #columns}&lt;/b&gt;&lt;/tt&gt;
  59. * config property. The &lt;tt&gt;&lt;b&gt;{@link #defaults}&lt;/b&gt;&lt;/tt&gt; config property can be used to apply defaults
  60. * for all columns, e.g.:&lt;/p&gt;&lt;pre&gt;&lt;code&gt;
  61. var colModel = new Ext.grid.ColumnModel({
  62. columns: [
  63. { header: &quot;Ticker&quot;, width: 60, menuDisabled: false},
  64. { header: &quot;Company Name&quot;, width: 150, id: 'company'},
  65. { header: &quot;Market Cap.&quot;},
  66. { header: &quot;$ Sales&quot;, renderer: money},
  67. { header: &quot;Employees&quot;, resizable: false}
  68. ],
  69. defaults: {
  70. sortable: true,
  71. menuDisabled: true,
  72. width: 100
  73. },
  74. listeners: {
  75. {@link #hiddenchange}: function(cm, colIndex, hidden) {
  76. saveConfig(colIndex, hidden);
  77. }
  78. }
  79. });
  80. &lt;/code&gt;&lt;/pre&gt;
  81. * &lt;p&gt;In both examples above, the ability to apply a CSS class to all cells in a column (including the
  82. * header) is demonstrated through the use of the &lt;b&gt;&lt;tt&gt;{@link Ext.grid.Column#id id}&lt;/tt&gt;&lt;/b&gt; config
  83. * option. This column could be styled by including the following css:&lt;/p&gt;&lt;pre&gt;&lt;code&gt;
  84. //add this css *after* the core css is loaded
  85. .x-grid3-td-company {
  86. color: red; // entire column will have red font
  87. }
  88. // modify the header row only, adding an icon to the column header
  89. .x-grid3-hd-company {
  90. background: transparent
  91. url(../../resources/images/icons/silk/building.png)
  92. no-repeat 3px 3px ! important;
  93. padding-left:20px;
  94. }
  95. &lt;/code&gt;&lt;/pre&gt;
  96. * Note that the &quot;Company Name&quot; column could be specified as the
  97. * &lt;b&gt;&lt;tt&gt;{@link Ext.grid.GridPanel}.{@link Ext.grid.GridPanel#autoExpandColumn autoExpandColumn}&lt;/tt&gt;&lt;/b&gt;.
  98. * @constructor
  99. * @param {Mixed} config Specify either an Array of {@link Ext.grid.Column} configuration objects or specify
  100. * a configuration Object (see introductory section discussion utilizing Initialization Method 2 above).
  101. */
  102. Ext.grid.ColumnModel = Ext.extend(Ext.util.Observable, {
  103. <span id='Ext-grid-ColumnModel-cfg-defaultWidth'> /**
  104. </span> * @cfg {Number} defaultWidth (optional) The width of columns which have no &lt;tt&gt;{@link #width}&lt;/tt&gt;
  105. * specified (defaults to &lt;tt&gt;100&lt;/tt&gt;). This property shall preferably be configured through the
  106. * &lt;tt&gt;&lt;b&gt;{@link #defaults}&lt;/b&gt;&lt;/tt&gt; config property.
  107. */
  108. defaultWidth: 100,
  109. <span id='Ext-grid-ColumnModel-cfg-defaultSortable'> /**
  110. </span> * @cfg {Boolean} defaultSortable (optional) Default sortable of columns which have no
  111. * sortable specified (defaults to &lt;tt&gt;false&lt;/tt&gt;). This property shall preferably be configured
  112. * through the &lt;tt&gt;&lt;b&gt;{@link #defaults}&lt;/b&gt;&lt;/tt&gt; config property.
  113. */
  114. defaultSortable: false,
  115. <span id='Ext-grid-ColumnModel-cfg-columns'> /**
  116. </span> * @cfg {Array} columns An Array of object literals. The config options defined by
  117. * &lt;b&gt;{@link Ext.grid.Column}&lt;/b&gt; are the options which may appear in the object literal for each
  118. * individual column definition.
  119. */
  120. <span id='Ext-grid-ColumnModel-cfg-defaults'> /**
  121. </span> * @cfg {Object} defaults Object literal which will be used to apply {@link Ext.grid.Column}
  122. * configuration options to all &lt;tt&gt;&lt;b&gt;{@link #columns}&lt;/b&gt;&lt;/tt&gt;. Configuration options specified with
  123. * individual {@link Ext.grid.Column column} configs will supersede these &lt;tt&gt;&lt;b&gt;{@link #defaults}&lt;/b&gt;&lt;/tt&gt;.
  124. */
  125. constructor : function(config) {
  126. <span id='Ext-grid-ColumnModel-property-config'> /**
  127. </span> * An Array of {@link Ext.grid.Column Column definition} objects representing the configuration
  128. * of this ColumnModel. See {@link Ext.grid.Column} for the configuration properties that may
  129. * be specified.
  130. * @property config
  131. * @type Array
  132. */
  133. if (config.columns) {
  134. Ext.apply(this, config);
  135. this.setConfig(config.columns, true);
  136. } else {
  137. this.setConfig(config, true);
  138. }
  139. this.addEvents(
  140. <span id='Ext-grid-ColumnModel-event-widthchange'> /**
  141. </span> * @event widthchange
  142. * Fires when the width of a column is programmaticially changed using
  143. * &lt;code&gt;{@link #setColumnWidth}&lt;/code&gt;.
  144. * Note internal resizing suppresses the event from firing. See also
  145. * {@link Ext.grid.GridPanel}.&lt;code&gt;{@link #columnresize}&lt;/code&gt;.
  146. * @param {ColumnModel} this
  147. * @param {Number} columnIndex The column index
  148. * @param {Number} newWidth The new width
  149. */
  150. &quot;widthchange&quot;,
  151. <span id='Ext-grid-ColumnModel-event-headerchange'> /**
  152. </span> * @event headerchange
  153. * Fires when the text of a header changes.
  154. * @param {ColumnModel} this
  155. * @param {Number} columnIndex The column index
  156. * @param {String} newText The new header text
  157. */
  158. &quot;headerchange&quot;,
  159. <span id='Ext-grid-ColumnModel-event-hiddenchange'> /**
  160. </span> * @event hiddenchange
  161. * Fires when a column is hidden or &quot;unhidden&quot;.
  162. * @param {ColumnModel} this
  163. * @param {Number} columnIndex The column index
  164. * @param {Boolean} hidden true if hidden, false otherwise
  165. */
  166. &quot;hiddenchange&quot;,
  167. <span id='Ext-grid-ColumnModel-event-columnmoved'> /**
  168. </span> * @event columnmoved
  169. * Fires when a column is moved.
  170. * @param {ColumnModel} this
  171. * @param {Number} oldIndex
  172. * @param {Number} newIndex
  173. */
  174. &quot;columnmoved&quot;,
  175. <span id='Ext-grid-ColumnModel-event-configchange'> /**
  176. </span> * @event configchange
  177. * Fires when the configuration is changed
  178. * @param {ColumnModel} this
  179. */
  180. &quot;configchange&quot;
  181. );
  182. Ext.grid.ColumnModel.superclass.constructor.call(this);
  183. },
  184. <span id='Ext-grid-ColumnModel-method-getColumnId'> /**
  185. </span> * Returns the id of the column at the specified index.
  186. * @param {Number} index The column index
  187. * @return {String} the id
  188. */
  189. getColumnId : function(index) {
  190. return this.config[index].id;
  191. },
  192. <span id='Ext-grid-ColumnModel-method-getColumnAt'> getColumnAt : function(index) {
  193. </span> return this.config[index];
  194. },
  195. <span id='Ext-grid-ColumnModel-method-setConfig'> /**
  196. </span> * &lt;p&gt;Reconfigures this column model according to the passed Array of column definition objects.
  197. * For a description of the individual properties of a column definition object, see the
  198. * &lt;a href=&quot;#Ext.grid.ColumnModel-configs&quot;&gt;Config Options&lt;/a&gt;.&lt;/p&gt;
  199. * &lt;p&gt;Causes the {@link #configchange} event to be fired. A {@link Ext.grid.GridPanel GridPanel}
  200. * using this ColumnModel will listen for this event and refresh its UI automatically.&lt;/p&gt;
  201. * @param {Array} config Array of Column definition objects.
  202. * @param {Boolean} initial Specify &lt;tt&gt;true&lt;/tt&gt; to bypass cleanup which deletes the &lt;tt&gt;totalWidth&lt;/tt&gt;
  203. * and destroys existing editors.
  204. */
  205. setConfig : function(config, initial) {
  206. var i, c, len;
  207. if (!initial) { // cleanup
  208. delete this.totalWidth;
  209. for (i = 0, len = this.config.length; i &lt; len; i++) {
  210. c = this.config[i];
  211. if (c.setEditor) {
  212. //check here, in case we have a special column like a CheckboxSelectionModel
  213. c.setEditor(null);
  214. }
  215. }
  216. }
  217. // backward compatibility
  218. this.defaults = Ext.apply({
  219. width: this.defaultWidth,
  220. sortable: this.defaultSortable
  221. }, this.defaults);
  222. this.config = config;
  223. this.lookup = {};
  224. for (i = 0, len = config.length; i &lt; len; i++) {
  225. c = Ext.applyIf(config[i], this.defaults);
  226. // if no id, create one using column's ordinal position
  227. if (Ext.isEmpty(c.id)) {
  228. c.id = i;
  229. }
  230. if (!c.isColumn) {
  231. var Cls = Ext.grid.Column.types[c.xtype || 'gridcolumn'];
  232. c = new Cls(c);
  233. config[i] = c;
  234. }
  235. this.lookup[c.id] = c;
  236. }
  237. if (!initial) {
  238. this.fireEvent('configchange', this);
  239. }
  240. },
  241. <span id='Ext-grid-ColumnModel-method-getColumnById'> /**
  242. </span> * Returns the column for a specified id.
  243. * @param {String} id The column id
  244. * @return {Object} the column
  245. */
  246. getColumnById : function(id) {
  247. return this.lookup[id];
  248. },
  249. <span id='Ext-grid-ColumnModel-method-getIndexById'> /**
  250. </span> * Returns the index for a specified column id.
  251. * @param {String} id The column id
  252. * @return {Number} the index, or -1 if not found
  253. */
  254. getIndexById : function(id) {
  255. for (var i = 0, len = this.config.length; i &lt; len; i++) {
  256. if (this.config[i].id == id) {
  257. return i;
  258. }
  259. }
  260. return -1;
  261. },
  262. <span id='Ext-grid-ColumnModel-method-moveColumn'> /**
  263. </span> * Moves a column from one position to another.
  264. * @param {Number} oldIndex The index of the column to move.
  265. * @param {Number} newIndex The position at which to reinsert the coolumn.
  266. */
  267. moveColumn : function(oldIndex, newIndex) {
  268. var config = this.config,
  269. c = config[oldIndex];
  270. config.splice(oldIndex, 1);
  271. config.splice(newIndex, 0, c);
  272. this.dataMap = null;
  273. this.fireEvent(&quot;columnmoved&quot;, this, oldIndex, newIndex);
  274. },
  275. <span id='Ext-grid-ColumnModel-method-getColumnCount'> /**
  276. </span> * Returns the number of columns.
  277. * @param {Boolean} visibleOnly Optional. Pass as true to only include visible columns.
  278. * @return {Number}
  279. */
  280. getColumnCount : function(visibleOnly) {
  281. var length = this.config.length,
  282. c = 0,
  283. i;
  284. if (visibleOnly === true) {
  285. for (i = 0; i &lt; length; i++) {
  286. if (!this.isHidden(i)) {
  287. c++;
  288. }
  289. }
  290. return c;
  291. }
  292. return length;
  293. },
  294. <span id='Ext-grid-ColumnModel-method-getColumnsBy'> /**
  295. </span> * Returns the column configs that return true by the passed function that is called
  296. * with (columnConfig, index)
  297. &lt;pre&gt;&lt;code&gt;
  298. // returns an array of column config objects for all hidden columns
  299. var columns = grid.getColumnModel().getColumnsBy(function(c){
  300. return c.hidden;
  301. });
  302. &lt;/code&gt;&lt;/pre&gt;
  303. * @param {Function} fn A function which, when passed a {@link Ext.grid.Column Column} object, must
  304. * return &lt;code&gt;true&lt;/code&gt; if the column is to be included in the returned Array.
  305. * @param {Object} scope (optional) The scope (&lt;code&gt;this&lt;/code&gt; reference) in which the function
  306. * is executed. Defaults to this ColumnModel.
  307. * @return {Array} result
  308. */
  309. getColumnsBy : function(fn, scope) {
  310. var config = this.config,
  311. length = config.length,
  312. result = [],
  313. i, c;
  314. for (i = 0; i &lt; length; i++){
  315. c = config[i];
  316. if (fn.call(scope || this, c, i) === true) {
  317. result[result.length] = c;
  318. }
  319. }
  320. return result;
  321. },
  322. <span id='Ext-grid-ColumnModel-method-isSortable'> /**
  323. </span> * Returns true if the specified column is sortable.
  324. * @param {Number} col The column index
  325. * @return {Boolean}
  326. */
  327. isSortable : function(col) {
  328. return !!this.config[col].sortable;
  329. },
  330. <span id='Ext-grid-ColumnModel-method-isMenuDisabled'> /**
  331. </span> * Returns true if the specified column menu is disabled.
  332. * @param {Number} col The column index
  333. * @return {Boolean}
  334. */
  335. isMenuDisabled : function(col) {
  336. return !!this.config[col].menuDisabled;
  337. },
  338. <span id='Ext-grid-ColumnModel-method-getRenderer'> /**
  339. </span> * Returns the rendering (formatting) function defined for the column.
  340. * @param {Number} col The column index.
  341. * @return {Function} The function used to render the cell. See {@link #setRenderer}.
  342. */
  343. getRenderer : function(col) {
  344. return this.config[col].renderer || Ext.grid.ColumnModel.defaultRenderer;
  345. },
  346. <span id='Ext-grid-ColumnModel-method-getRendererScope'> getRendererScope : function(col) {
  347. </span> return this.config[col].scope;
  348. },
  349. <span id='Ext-grid-ColumnModel-method-setRenderer'> /**
  350. </span> * Sets the rendering (formatting) function for a column. See {@link Ext.util.Format} for some
  351. * default formatting functions.
  352. * @param {Number} col The column index
  353. * @param {Function} fn The function to use to process the cell's raw data
  354. * to return HTML markup for the grid view. The render function is called with
  355. * the following parameters:&lt;ul&gt;
  356. * &lt;li&gt;&lt;b&gt;value&lt;/b&gt; : Object&lt;p class=&quot;sub-desc&quot;&gt;The data value for the cell.&lt;/p&gt;&lt;/li&gt;
  357. * &lt;li&gt;&lt;b&gt;metadata&lt;/b&gt; : Object&lt;p class=&quot;sub-desc&quot;&gt;An object in which you may set the following attributes:&lt;ul&gt;
  358. * &lt;li&gt;&lt;b&gt;css&lt;/b&gt; : String&lt;p class=&quot;sub-desc&quot;&gt;A CSS class name to add to the cell's TD element.&lt;/p&gt;&lt;/li&gt;
  359. * &lt;li&gt;&lt;b&gt;attr&lt;/b&gt; : String&lt;p class=&quot;sub-desc&quot;&gt;An HTML attribute definition string to apply to the data container element &lt;i&gt;within&lt;/i&gt; the table cell
  360. * (e.g. 'style=&quot;color:red;&quot;').&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/p&gt;&lt;/li&gt;
  361. * &lt;li&gt;&lt;b&gt;record&lt;/b&gt; : Ext.data.record&lt;p class=&quot;sub-desc&quot;&gt;The {@link Ext.data.Record} from which the data was extracted.&lt;/p&gt;&lt;/li&gt;
  362. * &lt;li&gt;&lt;b&gt;rowIndex&lt;/b&gt; : Number&lt;p class=&quot;sub-desc&quot;&gt;Row index&lt;/p&gt;&lt;/li&gt;
  363. * &lt;li&gt;&lt;b&gt;colIndex&lt;/b&gt; : Number&lt;p class=&quot;sub-desc&quot;&gt;Column index&lt;/p&gt;&lt;/li&gt;
  364. * &lt;li&gt;&lt;b&gt;store&lt;/b&gt; : Ext.data.Store&lt;p class=&quot;sub-desc&quot;&gt;The {@link Ext.data.Store} object from which the Record was extracted.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;
  365. */
  366. setRenderer : function(col, fn) {
  367. this.config[col].renderer = fn;
  368. },
  369. <span id='Ext-grid-ColumnModel-method-getColumnWidth'> /**
  370. </span> * Returns the width for the specified column.
  371. * @param {Number} col The column index
  372. * @return {Number}
  373. */
  374. getColumnWidth : function(col) {
  375. var width = this.config[col].width;
  376. if(typeof width != 'number'){
  377. width = this.defaultWidth;
  378. }
  379. return width;
  380. },
  381. <span id='Ext-grid-ColumnModel-method-setColumnWidth'> /**
  382. </span> * Sets the width for a column.
  383. * @param {Number} col The column index
  384. * @param {Number} width The new width
  385. * @param {Boolean} suppressEvent True to suppress firing the &lt;code&gt;{@link #widthchange}&lt;/code&gt;
  386. * event. Defaults to false.
  387. */
  388. setColumnWidth : function(col, width, suppressEvent) {
  389. this.config[col].width = width;
  390. this.totalWidth = null;
  391. if (!suppressEvent) {
  392. this.fireEvent(&quot;widthchange&quot;, this, col, width);
  393. }
  394. },
  395. <span id='Ext-grid-ColumnModel-method-getTotalWidth'> /**
  396. </span> * Returns the total width of all columns.
  397. * @param {Boolean} includeHidden True to include hidden column widths
  398. * @return {Number}
  399. */
  400. getTotalWidth : function(includeHidden) {
  401. if (!this.totalWidth) {
  402. this.totalWidth = 0;
  403. for (var i = 0, len = this.config.length; i &lt; len; i++) {
  404. if (includeHidden || !this.isHidden(i)) {
  405. this.totalWidth += this.getColumnWidth(i);
  406. }
  407. }
  408. }
  409. return this.totalWidth;
  410. },
  411. <span id='Ext-grid-ColumnModel-method-getColumnHeader'> /**
  412. </span> * Returns the header for the specified column.
  413. * @param {Number} col The column index
  414. * @return {String}
  415. */
  416. getColumnHeader : function(col) {
  417. return this.config[col].header;
  418. },
  419. <span id='Ext-grid-ColumnModel-method-setColumnHeader'> /**
  420. </span> * Sets the header for a column.
  421. * @param {Number} col The column index
  422. * @param {String} header The new header
  423. */
  424. setColumnHeader : function(col, header) {
  425. this.config[col].header = header;
  426. this.fireEvent(&quot;headerchange&quot;, this, col, header);
  427. },
  428. <span id='Ext-grid-ColumnModel-method-getColumnTooltip'> /**
  429. </span> * Returns the tooltip for the specified column.
  430. * @param {Number} col The column index
  431. * @return {String}
  432. */
  433. getColumnTooltip : function(col) {
  434. return this.config[col].tooltip;
  435. },
  436. <span id='Ext-grid-ColumnModel-method-setColumnTooltip'> /**
  437. </span> * Sets the tooltip for a column.
  438. * @param {Number} col The column index
  439. * @param {String} tooltip The new tooltip
  440. */
  441. setColumnTooltip : function(col, tooltip) {
  442. this.config[col].tooltip = tooltip;
  443. },
  444. <span id='Ext-grid-ColumnModel-method-getDataIndex'> /**
  445. </span> * Returns the dataIndex for the specified column.
  446. &lt;pre&gt;&lt;code&gt;
  447. // Get field name for the column
  448. var fieldName = grid.getColumnModel().getDataIndex(columnIndex);
  449. &lt;/code&gt;&lt;/pre&gt;
  450. * @param {Number} col The column index
  451. * @return {String} The column's dataIndex
  452. */
  453. getDataIndex : function(col) {
  454. return this.config[col].dataIndex;
  455. },
  456. <span id='Ext-grid-ColumnModel-method-setDataIndex'> /**
  457. </span> * Sets the dataIndex for a column.
  458. * @param {Number} col The column index
  459. * @param {String} dataIndex The new dataIndex
  460. */
  461. setDataIndex : function(col, dataIndex) {
  462. this.config[col].dataIndex = dataIndex;
  463. },
  464. <span id='Ext-grid-ColumnModel-method-findColumnIndex'> /**
  465. </span> * Finds the index of the first matching column for the given dataIndex.
  466. * @param {String} col The dataIndex to find
  467. * @return {Number} The column index, or -1 if no match was found
  468. */
  469. findColumnIndex : function(dataIndex) {
  470. var c = this.config;
  471. for(var i = 0, len = c.length; i &lt; len; i++){
  472. if(c[i].dataIndex == dataIndex){
  473. return i;
  474. }
  475. }
  476. return -1;
  477. },
  478. <span id='Ext-grid-ColumnModel-method-isCellEditable'> /**
  479. </span> * Returns true if the cell is editable.
  480. &lt;pre&gt;&lt;code&gt;
  481. var store = new Ext.data.Store({...});
  482. var colModel = new Ext.grid.ColumnModel({
  483. columns: [...],
  484. isCellEditable: function(col, row) {
  485. var record = store.getAt(row);
  486. if (record.get('readonly')) { // replace with your condition
  487. return false;
  488. }
  489. return Ext.grid.ColumnModel.prototype.isCellEditable.call(this, col, row);
  490. }
  491. });
  492. var grid = new Ext.grid.GridPanel({
  493. store: store,
  494. colModel: colModel,
  495. ...
  496. });
  497. &lt;/code&gt;&lt;/pre&gt;
  498. * @param {Number} colIndex The column index
  499. * @param {Number} rowIndex The row index
  500. * @return {Boolean}
  501. */
  502. isCellEditable : function(colIndex, rowIndex) {
  503. var c = this.config[colIndex],
  504. ed = c.editable;
  505. //force boolean
  506. return !!(ed || (!Ext.isDefined(ed) &amp;&amp; c.editor));
  507. },
  508. <span id='Ext-grid-ColumnModel-method-getCellEditor'> /**
  509. </span> * Returns the editor defined for the cell/column.
  510. * @param {Number} colIndex The column index
  511. * @param {Number} rowIndex The row index
  512. * @return {Ext.Editor} The {@link Ext.Editor Editor} that was created to wrap
  513. * the {@link Ext.form.Field Field} used to edit the cell.
  514. */
  515. getCellEditor : function(colIndex, rowIndex) {
  516. return this.config[colIndex].getCellEditor(rowIndex);
  517. },
  518. <span id='Ext-grid-ColumnModel-method-setEditable'> /**
  519. </span> * Sets if a column is editable.
  520. * @param {Number} col The column index
  521. * @param {Boolean} editable True if the column is editable
  522. */
  523. setEditable : function(col, editable) {
  524. this.config[col].editable = editable;
  525. },
  526. <span id='Ext-grid-ColumnModel-method-isHidden'> /**
  527. </span> * Returns &lt;tt&gt;true&lt;/tt&gt; if the column is &lt;code&gt;{@link Ext.grid.Column#hidden hidden}&lt;/code&gt;,
  528. * &lt;tt&gt;false&lt;/tt&gt; otherwise.
  529. * @param {Number} colIndex The column index
  530. * @return {Boolean}
  531. */
  532. isHidden : function(colIndex) {
  533. return !!this.config[colIndex].hidden; // ensure returns boolean
  534. },
  535. <span id='Ext-grid-ColumnModel-method-isFixed'> /**
  536. </span> * Returns &lt;tt&gt;true&lt;/tt&gt; if the column is &lt;code&gt;{@link Ext.grid.Column#fixed fixed}&lt;/code&gt;,
  537. * &lt;tt&gt;false&lt;/tt&gt; otherwise.
  538. * @param {Number} colIndex The column index
  539. * @return {Boolean}
  540. */
  541. isFixed : function(colIndex) {
  542. return !!this.config[colIndex].fixed;
  543. },
  544. <span id='Ext-grid-ColumnModel-method-isResizable'> /**
  545. </span> * Returns true if the column can be resized
  546. * @return {Boolean}
  547. */
  548. isResizable : function(colIndex) {
  549. return colIndex &gt;= 0 &amp;&amp; this.config[colIndex].resizable !== false &amp;&amp; this.config[colIndex].fixed !== true;
  550. },
  551. <span id='Ext-grid-ColumnModel-method-setHidden'> /**
  552. </span> * Sets if a column is hidden.
  553. &lt;pre&gt;&lt;code&gt;
  554. myGrid.getColumnModel().setHidden(0, true); // hide column 0 (0 = the first column).
  555. &lt;/code&gt;&lt;/pre&gt;
  556. * @param {Number} colIndex The column index
  557. * @param {Boolean} hidden True if the column is hidden
  558. */
  559. setHidden : function(colIndex, hidden) {
  560. var c = this.config[colIndex];
  561. if(c.hidden !== hidden){
  562. c.hidden = hidden;
  563. this.totalWidth = null;
  564. this.fireEvent(&quot;hiddenchange&quot;, this, colIndex, hidden);
  565. }
  566. },
  567. <span id='Ext-grid-ColumnModel-method-setEditor'> /**
  568. </span> * Sets the editor for a column and destroys the prior editor.
  569. * @param {Number} col The column index
  570. * @param {Object} editor The editor object
  571. */
  572. setEditor : function(col, editor) {
  573. this.config[col].setEditor(editor);
  574. },
  575. <span id='Ext-grid-ColumnModel-method-destroy'> /**
  576. </span> * Destroys this column model by purging any event listeners. Destroys and dereferences all Columns.
  577. */
  578. destroy : function() {
  579. var length = this.config.length,
  580. i = 0;
  581. for (; i &lt; length; i++){
  582. this.config[i].destroy(); // Column's destroy encapsulates all cleanup.
  583. }
  584. delete this.config;
  585. delete this.lookup;
  586. this.purgeListeners();
  587. },
  588. <span id='Ext-grid-ColumnModel-method-setState'> /**
  589. </span> * @private
  590. * Setup any saved state for the column, ensures that defaults are applied.
  591. */
  592. setState : function(col, state) {
  593. state = Ext.applyIf(state, this.defaults);
  594. Ext.apply(this.config[col], state);
  595. }
  596. });
  597. // private
  598. Ext.grid.ColumnModel.defaultRenderer = function(value) {
  599. if (typeof value == &quot;string&quot; &amp;&amp; value.length &lt; 1) {
  600. return &quot;&amp;#160;&quot;;
  601. }
  602. return value;
  603. };</pre>
  604. </body>
  605. </html>