Web Interface For Lite Argus Control modules
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.

664 lines
25 KiB

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