/hippo/src/main/webapp/ext/src/widgets/grid/GridPanel.js

http://hdbc.googlecode.com/ · JavaScript · 952 lines · 291 code · 41 blank · 620 comment · 41 complexity · 2f681cbcb1f37753e9aebf25ba18257b MD5 · raw file

  1. /*!
  2. * Ext JS Library 3.0.0
  3. * Copyright(c) 2006-2009 Ext JS, LLC
  4. * licensing@extjs.com
  5. * http://www.extjs.com/license
  6. */
  7. /**
  8. * @class Ext.grid.GridPanel
  9. * @extends Ext.Panel
  10. * <p>This class represents the primary interface of a component based grid control to represent data
  11. * in a tabular format of rows and columns. The GridPanel is composed of the following:</p>
  12. * <div class="mdetail-params"><ul>
  13. * <li><b>{@link Ext.data.Store Store}</b> : The Model holding the data records (rows)
  14. * <div class="sub-desc"></div></li>
  15. * <li><b>{@link Ext.grid.ColumnModel Column model}</b> : Column makeup
  16. * <div class="sub-desc"></div></li>
  17. * <li><b>{@link Ext.grid.GridView View}</b> : Encapsulates the user interface
  18. * <div class="sub-desc"></div></li>
  19. * <li><b>{@link Ext.grid.AbstractSelectionModel selection model}</b> : Selection behavior
  20. * <div class="sub-desc"></div></li>
  21. * </ul></div>
  22. * <p>Example usage:</p>
  23. * <pre><code>
  24. var grid = new Ext.grid.GridPanel({
  25. {@link #store}: new (@link Ext.data.Store}({
  26. {@link Ext.data.Store#autoDestroy autoDestroy}: true,
  27. {@link Ext.data.Store#reader reader}: reader,
  28. {@link Ext.data.Store#data data}: xg.dummyData
  29. }),
  30. {@link #columns}: [
  31. {id: 'company', header: 'Company', width: 200, sortable: true, dataIndex: 'company'},
  32. {header: 'Price', width: 120, sortable: true, renderer: Ext.util.Format.usMoney, dataIndex: 'price'},
  33. {header: 'Change', width: 120, sortable: true, dataIndex: 'change'},
  34. {header: '% Change', width: 120, sortable: true, dataIndex: 'pctChange'},
  35. // instead of specifying renderer: Ext.util.Format.dateRenderer('m/d/Y') use xtype
  36. {header: 'Last Updated', width: 135, sortable: true, dataIndex: 'lastChange', xtype: 'datecolumn', format: 'M d, Y'}
  37. ],
  38. {@link #viewConfig}: {
  39. {@link Ext.grid.GridView#forceFit forceFit}: true,
  40. // Return CSS class to apply to rows depending upon data values
  41. {@link Ext.grid.GridView#getRowClass getRowClass}: function(record, index) {
  42. var c = record.{@link Ext.data.Record#get get}('change');
  43. if (c < 0) {
  44. return 'price-fall';
  45. } else if (c > 0) {
  46. return 'price-rise';
  47. }
  48. }
  49. },
  50. {@link #sm}: new Ext.grid.RowSelectionModel({singleSelect:true}),
  51. width: 600,
  52. height: 300,
  53. frame: true,
  54. title: 'Framed with Row Selection and Horizontal Scrolling',
  55. iconCls: 'icon-grid'
  56. });
  57. * </code></pre>
  58. * <p><b><u>Notes:</u></b></p>
  59. * <div class="mdetail-params"><ul>
  60. * <li>Although this class inherits many configuration options from base classes, some of them
  61. * (such as autoScroll, autoWidth, layout, items, etc) are not used by this class, and will
  62. * have no effect.</li>
  63. * <li>A grid <b>requires</b> a width in which to scroll its columns, and a height in which to
  64. * scroll its rows. These dimensions can either be set explicitly through the
  65. * <tt>{@link Ext.BoxComponent#height height}</tt> and <tt>{@link Ext.BoxComponent#width width}</tt>
  66. * configuration options or implicitly set by using the grid as a child item of a
  67. * {@link Ext.Container Container} which will have a {@link Ext.Container#layout layout manager}
  68. * provide the sizing of its child items (for example the Container of the Grid may specify
  69. * <tt>{@link Ext.Container#layout layout}:'fit'</tt>).</li>
  70. * <li>To access the data in a Grid, it is necessary to use the data model encapsulated
  71. * by the {@link #store Store}. See the {@link #cellclick} event for more details.</li>
  72. * </ul></div>
  73. * @constructor
  74. * @param {Object} config The config object
  75. * @xtype grid
  76. */
  77. Ext.grid.GridPanel = Ext.extend(Ext.Panel, {
  78. /**
  79. * @cfg {String} autoExpandColumn
  80. * <p>The <tt>{@link Ext.grid.Column#id id}</tt> of a {@link Ext.grid.Column column} in
  81. * this grid that should expand to fill unused space. This value specified here can not
  82. * be <tt>0</tt>.</p>
  83. * <br><p><b>Note</b>: If the Grid's {@link Ext.grid.GridView view} is configured with
  84. * <tt>{@link Ext.grid.GridView#forceFit forceFit}=true</tt> the <tt>autoExpandColumn</tt>
  85. * is ignored. See {@link Ext.grid.Column}.<tt>{@link Ext.grid.Column#width width}</tt>
  86. * for additional details.</p>
  87. * <p>See <tt>{@link #autoExpandMax}</tt> and <tt>{@link #autoExpandMin}</tt> also.</p>
  88. */
  89. autoExpandColumn : false,
  90. /**
  91. * @cfg {Number} autoExpandMax The maximum width the <tt>{@link #autoExpandColumn}</tt>
  92. * can have (if enabled). Defaults to <tt>1000</tt>.
  93. */
  94. autoExpandMax : 1000,
  95. /**
  96. * @cfg {Number} autoExpandMin The minimum width the <tt>{@link #autoExpandColumn}</tt>
  97. * can have (if enabled). Defaults to <tt>50</tt>.
  98. */
  99. autoExpandMin : 50,
  100. /**
  101. * @cfg {Boolean} columnLines <tt>true</tt> to add css for column separation lines.
  102. * Default is <tt>false</tt>.
  103. */
  104. columnLines : false,
  105. /**
  106. * @cfg {Object} cm Shorthand for <tt>{@link #colModel}</tt>.
  107. */
  108. /**
  109. * @cfg {Object} colModel The {@link Ext.grid.ColumnModel} to use when rendering the grid (required).
  110. */
  111. /**
  112. * @cfg {Array} columns An array of {@link Ext.grid.Column columns} to auto create a
  113. * {@link Ext.grid.ColumnModel}. The ColumnModel may be explicitly created via the
  114. * <tt>{@link #colModel}</tt> configuration property.
  115. */
  116. /**
  117. * @cfg {String} ddGroup The DD group this GridPanel belongs to. Defaults to <tt>'GridDD'</tt> if not specified.
  118. */
  119. /**
  120. * @cfg {String} ddText
  121. * Configures the text in the drag proxy. Defaults to:
  122. * <pre><code>
  123. * ddText : '{0} selected row{1}'
  124. * </code></pre>
  125. * <tt>{0}</tt> is replaced with the number of selected rows.
  126. */
  127. ddText : '{0} selected row{1}',
  128. /**
  129. * @cfg {Boolean} deferRowRender <P>Defaults to <tt>true</tt> to enable deferred row rendering.</p>
  130. * <p>This allows the GridPanel to be initially rendered empty, with the expensive update of the row
  131. * structure deferred so that layouts with GridPanels appear more quickly.</p>
  132. */
  133. deferRowRender : true,
  134. /**
  135. * @cfg {Boolean} disableSelection <p><tt>true</tt> to disable selections in the grid. Defaults to <tt>false</tt>.</p>
  136. * <p>Ignored if a {@link #selModel SelectionModel} is specified.</p>
  137. */
  138. /**
  139. * @cfg {Boolean} enableColumnResize <tt>false</tt> to turn off column resizing for the whole grid. Defaults to <tt>true</tt>.
  140. */
  141. /**
  142. * @cfg {Boolean} enableColumnHide Defaults to <tt>true</tt> to enable hiding of columns with the header context menu.
  143. */
  144. enableColumnHide : true,
  145. /**
  146. * @cfg {Boolean} enableColumnMove Defaults to <tt>true</tt> to enable drag and drop reorder of columns. <tt>false</tt>
  147. * to turn off column reordering via drag drop.
  148. */
  149. enableColumnMove : true,
  150. /**
  151. * @cfg {Boolean} enableDragDrop <p>Enables dragging of the selected rows of the GridPanel. Defaults to <tt>false</tt>.</p>
  152. * <p>Setting this to <b><tt>true</tt></b> causes this GridPanel's {@link #getView GridView} to
  153. * create an instance of {@link Ext.grid.GridDragZone}. <b>Note</b>: this is available only <b>after</b>
  154. * the Grid has been rendered as the GridView's <tt>{@link Ext.grid.GridView#dragZone dragZone}</tt>
  155. * property.</p>
  156. * <p>A cooperating {@link Ext.dd.DropZone DropZone} must be created who's implementations of
  157. * {@link Ext.dd.DropZone#onNodeEnter onNodeEnter}, {@link Ext.dd.DropZone#onNodeOver onNodeOver},
  158. * {@link Ext.dd.DropZone#onNodeOut onNodeOut} and {@link Ext.dd.DropZone#onNodeDrop onNodeDrop} are able
  159. * to process the {@link Ext.grid.GridDragZone#getDragData data} which is provided.</p>
  160. */
  161. enableDragDrop : false,
  162. /**
  163. * @cfg {Boolean} enableHdMenu Defaults to <tt>true</tt> to enable the drop down button for menu in the headers.
  164. */
  165. enableHdMenu : true,
  166. /**
  167. * @cfg {Boolean} hideHeaders True to hide the grid's header. Defaults to <code>false</code>.
  168. */
  169. /**
  170. * @cfg {Object} loadMask An {@link Ext.LoadMask} config or true to mask the grid while
  171. * loading. Defaults to <code>false</code>.
  172. */
  173. loadMask : false,
  174. /**
  175. * @cfg {Number} maxHeight Sets the maximum height of the grid - ignored if <tt>autoHeight</tt> is not on.
  176. */
  177. /**
  178. * @cfg {Number} minColumnWidth The minimum width a column can be resized to. Defaults to <tt>25</tt>.
  179. */
  180. minColumnWidth : 25,
  181. /**
  182. * @cfg {Object} sm Shorthand for <tt>{@link #selModel}</tt>.
  183. */
  184. /**
  185. * @cfg {Object} selModel Any subclass of {@link Ext.grid.AbstractSelectionModel} that will provide
  186. * the selection model for the grid (defaults to {@link Ext.grid.RowSelectionModel} if not specified).
  187. */
  188. /**
  189. * @cfg {Ext.data.Store} store The {@link Ext.data.Store} the grid should use as its data source (required).
  190. */
  191. /**
  192. * @cfg {Boolean} stripeRows <tt>true</tt> to stripe the rows. Default is <tt>false</tt>.
  193. * <p>This causes the CSS class <tt><b>x-grid3-row-alt</b></tt> to be added to alternate rows of
  194. * the grid. A default CSS rule is provided which sets a background colour, but you can override this
  195. * with a rule which either overrides the <b>background-color</b> style using the '!important'
  196. * modifier, or which uses a CSS selector of higher specificity.</p>
  197. */
  198. stripeRows : false,
  199. /**
  200. * @cfg {Boolean} trackMouseOver True to highlight rows when the mouse is over. Default is <tt>true</tt>
  201. * for GridPanel, but <tt>false</tt> for EditorGridPanel.
  202. */
  203. trackMouseOver : true,
  204. /**
  205. * @cfg {Array} stateEvents
  206. * An array of events that, when fired, should trigger this component to save its state.
  207. * Defaults to:<pre><code>
  208. * stateEvents: ['columnmove', 'columnresize', 'sortchange']
  209. * </code></pre>
  210. * <p>These can be any types of events supported by this component, including browser or
  211. * custom events (e.g., <tt>['click', 'customerchange']</tt>).</p>
  212. * <p>See {@link Ext.Component#stateful} for an explanation of saving and restoring
  213. * Component state.</p>
  214. */
  215. stateEvents : ['columnmove', 'columnresize', 'sortchange'],
  216. /**
  217. * @cfg {Object} view The {@link Ext.grid.GridView} used by the grid. This can be set
  218. * before a call to {@link Ext.Component#render render()}.
  219. */
  220. view : null,
  221. /**
  222. * @cfg {Object} viewConfig A config object that will be applied to the grid's UI view. Any of
  223. * the config options available for {@link Ext.grid.GridView} can be specified here. This option
  224. * is ignored if <tt>{@link #view}</tt> is specified.
  225. */
  226. // private
  227. rendered : false,
  228. // private
  229. viewReady : false,
  230. // private
  231. initComponent : function(){
  232. Ext.grid.GridPanel.superclass.initComponent.call(this);
  233. if(this.columnLines){
  234. this.cls = (this.cls || '') + ' x-grid-with-col-lines';
  235. }
  236. // override any provided value since it isn't valid
  237. // and is causing too many bug reports ;)
  238. this.autoScroll = false;
  239. this.autoWidth = false;
  240. if(Ext.isArray(this.columns)){
  241. this.colModel = new Ext.grid.ColumnModel(this.columns);
  242. delete this.columns;
  243. }
  244. // check and correct shorthanded configs
  245. if(this.ds){
  246. this.store = this.ds;
  247. delete this.ds;
  248. }
  249. if(this.cm){
  250. this.colModel = this.cm;
  251. delete this.cm;
  252. }
  253. if(this.sm){
  254. this.selModel = this.sm;
  255. delete this.sm;
  256. }
  257. this.store = Ext.StoreMgr.lookup(this.store);
  258. this.addEvents(
  259. // raw events
  260. /**
  261. * @event click
  262. * The raw click event for the entire grid.
  263. * @param {Ext.EventObject} e
  264. */
  265. 'click',
  266. /**
  267. * @event dblclick
  268. * The raw dblclick event for the entire grid.
  269. * @param {Ext.EventObject} e
  270. */
  271. 'dblclick',
  272. /**
  273. * @event contextmenu
  274. * The raw contextmenu event for the entire grid.
  275. * @param {Ext.EventObject} e
  276. */
  277. 'contextmenu',
  278. /**
  279. * @event mousedown
  280. * The raw mousedown event for the entire grid.
  281. * @param {Ext.EventObject} e
  282. */
  283. 'mousedown',
  284. /**
  285. * @event mouseup
  286. * The raw mouseup event for the entire grid.
  287. * @param {Ext.EventObject} e
  288. */
  289. 'mouseup',
  290. /**
  291. * @event mouseover
  292. * The raw mouseover event for the entire grid.
  293. * @param {Ext.EventObject} e
  294. */
  295. 'mouseover',
  296. /**
  297. * @event mouseout
  298. * The raw mouseout event for the entire grid.
  299. * @param {Ext.EventObject} e
  300. */
  301. 'mouseout',
  302. /**
  303. * @event keypress
  304. * The raw keypress event for the entire grid.
  305. * @param {Ext.EventObject} e
  306. */
  307. 'keypress',
  308. /**
  309. * @event keydown
  310. * The raw keydown event for the entire grid.
  311. * @param {Ext.EventObject} e
  312. */
  313. 'keydown',
  314. // custom events
  315. /**
  316. * @event cellmousedown
  317. * Fires before a cell is clicked
  318. * @param {Grid} this
  319. * @param {Number} rowIndex
  320. * @param {Number} columnIndex
  321. * @param {Ext.EventObject} e
  322. */
  323. 'cellmousedown',
  324. /**
  325. * @event rowmousedown
  326. * Fires before a row is clicked
  327. * @param {Grid} this
  328. * @param {Number} rowIndex
  329. * @param {Ext.EventObject} e
  330. */
  331. 'rowmousedown',
  332. /**
  333. * @event headermousedown
  334. * Fires before a header is clicked
  335. * @param {Grid} this
  336. * @param {Number} columnIndex
  337. * @param {Ext.EventObject} e
  338. */
  339. 'headermousedown',
  340. /**
  341. * @event cellclick
  342. * Fires when a cell is clicked.
  343. * The data for the cell is drawn from the {@link Ext.data.Record Record}
  344. * for this row. To access the data in the listener function use the
  345. * following technique:
  346. * <pre><code>
  347. function(grid, rowIndex, columnIndex, e) {
  348. var record = grid.getStore().getAt(rowIndex); // Get the Record
  349. var fieldName = grid.getColumnModel().getDataIndex(columnIndex); // Get field name
  350. var data = record.get(fieldName);
  351. }
  352. </code></pre>
  353. * @param {Grid} this
  354. * @param {Number} rowIndex
  355. * @param {Number} columnIndex
  356. * @param {Ext.EventObject} e
  357. */
  358. 'cellclick',
  359. /**
  360. * @event celldblclick
  361. * Fires when a cell is double clicked
  362. * @param {Grid} this
  363. * @param {Number} rowIndex
  364. * @param {Number} columnIndex
  365. * @param {Ext.EventObject} e
  366. */
  367. 'celldblclick',
  368. /**
  369. * @event rowclick
  370. * Fires when a row is clicked
  371. * @param {Grid} this
  372. * @param {Number} rowIndex
  373. * @param {Ext.EventObject} e
  374. */
  375. 'rowclick',
  376. /**
  377. * @event rowdblclick
  378. * Fires when a row is double clicked
  379. * @param {Grid} this
  380. * @param {Number} rowIndex
  381. * @param {Ext.EventObject} e
  382. */
  383. 'rowdblclick',
  384. /**
  385. * @event headerclick
  386. * Fires when a header is clicked
  387. * @param {Grid} this
  388. * @param {Number} columnIndex
  389. * @param {Ext.EventObject} e
  390. */
  391. 'headerclick',
  392. /**
  393. * @event headerdblclick
  394. * Fires when a header cell is double clicked
  395. * @param {Grid} this
  396. * @param {Number} columnIndex
  397. * @param {Ext.EventObject} e
  398. */
  399. 'headerdblclick',
  400. /**
  401. * @event rowcontextmenu
  402. * Fires when a row is right clicked
  403. * @param {Grid} this
  404. * @param {Number} rowIndex
  405. * @param {Ext.EventObject} e
  406. */
  407. 'rowcontextmenu',
  408. /**
  409. * @event cellcontextmenu
  410. * Fires when a cell is right clicked
  411. * @param {Grid} this
  412. * @param {Number} rowIndex
  413. * @param {Number} cellIndex
  414. * @param {Ext.EventObject} e
  415. */
  416. 'cellcontextmenu',
  417. /**
  418. * @event headercontextmenu
  419. * Fires when a header is right clicked
  420. * @param {Grid} this
  421. * @param {Number} columnIndex
  422. * @param {Ext.EventObject} e
  423. */
  424. 'headercontextmenu',
  425. /**
  426. * @event bodyscroll
  427. * Fires when the body element is scrolled
  428. * @param {Number} scrollLeft
  429. * @param {Number} scrollTop
  430. */
  431. 'bodyscroll',
  432. /**
  433. * @event columnresize
  434. * Fires when the user resizes a column
  435. * @param {Number} columnIndex
  436. * @param {Number} newSize
  437. */
  438. 'columnresize',
  439. /**
  440. * @event columnmove
  441. * Fires when the user moves a column
  442. * @param {Number} oldIndex
  443. * @param {Number} newIndex
  444. */
  445. 'columnmove',
  446. /**
  447. * @event sortchange
  448. * Fires when the grid's store sort changes
  449. * @param {Grid} this
  450. * @param {Object} sortInfo An object with the keys field and direction
  451. */
  452. 'sortchange',
  453. /**
  454. * @event reconfigure
  455. * Fires when the grid is reconfigured with a new store and/or column model.
  456. * @param {Grid} this
  457. * @param {Ext.data.Store} store The new store
  458. * @param {Ext.grid.ColumnModel} colModel The new column model
  459. */
  460. 'reconfigure'
  461. );
  462. },
  463. // private
  464. onRender : function(ct, position){
  465. Ext.grid.GridPanel.superclass.onRender.apply(this, arguments);
  466. var c = this.body;
  467. this.el.addClass('x-grid-panel');
  468. var view = this.getView();
  469. view.init(this);
  470. this.mon(c, {
  471. mousedown: this.onMouseDown,
  472. click: this.onClick,
  473. dblclick: this.onDblClick,
  474. contextmenu: this.onContextMenu,
  475. keydown: this.onKeyDown,
  476. scope: this
  477. });
  478. this.relayEvents(c, ['mousedown','mouseup','mouseover','mouseout','keypress']);
  479. this.getSelectionModel().init(this);
  480. this.view.render();
  481. },
  482. // private
  483. initEvents : function(){
  484. Ext.grid.GridPanel.superclass.initEvents.call(this);
  485. if(this.loadMask){
  486. this.loadMask = new Ext.LoadMask(this.bwrap,
  487. Ext.apply({store:this.store}, this.loadMask));
  488. }
  489. },
  490. initStateEvents : function(){
  491. Ext.grid.GridPanel.superclass.initStateEvents.call(this);
  492. this.mon(this.colModel, 'hiddenchange', this.saveState, this, {delay: 100});
  493. },
  494. applyState : function(state){
  495. var cm = this.colModel;
  496. var cs = state.columns;
  497. if(cs){
  498. for(var i = 0, len = cs.length; i < len; i++){
  499. var s = cs[i];
  500. var c = cm.getColumnById(s.id);
  501. if(c){
  502. c.hidden = s.hidden;
  503. c.width = s.width;
  504. var oldIndex = cm.getIndexById(s.id);
  505. if(oldIndex != i){
  506. cm.moveColumn(oldIndex, i);
  507. }
  508. }
  509. }
  510. }
  511. if(state.sort && this.store){
  512. this.store[this.store.remoteSort ? 'setDefaultSort' : 'sort'](state.sort.field, state.sort.direction);
  513. }
  514. delete state.columns;
  515. delete state.sort;
  516. Ext.grid.GridPanel.superclass.applyState.call(this, state);
  517. },
  518. getState : function(){
  519. var o = {columns: []};
  520. for(var i = 0, c; (c = this.colModel.config[i]); i++){
  521. o.columns[i] = {
  522. id: c.id,
  523. width: c.width
  524. };
  525. if(c.hidden){
  526. o.columns[i].hidden = true;
  527. }
  528. }
  529. if(this.store){
  530. var ss = this.store.getSortState();
  531. if(ss){
  532. o.sort = ss;
  533. }
  534. }
  535. return o;
  536. },
  537. // private
  538. afterRender : function(){
  539. Ext.grid.GridPanel.superclass.afterRender.call(this);
  540. this.view.layout();
  541. if(this.deferRowRender){
  542. this.view.afterRender.defer(10, this.view);
  543. }else{
  544. this.view.afterRender();
  545. }
  546. this.viewReady = true;
  547. },
  548. /**
  549. * <p>Reconfigures the grid to use a different Store and Column Model
  550. * and fires the 'reconfigure' event. The View will be bound to the new
  551. * objects and refreshed.</p>
  552. * <p>Be aware that upon reconfiguring a GridPanel, certain existing settings <i>may</i> become
  553. * invalidated. For example the configured {@link #autoExpandColumn} may no longer exist in the
  554. * new ColumnModel. Also, an existing {@link Ext.PagingToolbar PagingToolbar} will still be bound
  555. * to the old Store, and will need rebinding. Any {@link #plugins} might also need reconfiguring
  556. * with the new data.</p>
  557. * @param {Ext.data.Store} store The new {@link Ext.data.Store} object
  558. * @param {Ext.grid.ColumnModel} colModel The new {@link Ext.grid.ColumnModel} object
  559. */
  560. reconfigure : function(store, colModel){
  561. if(this.loadMask){
  562. this.loadMask.destroy();
  563. this.loadMask = new Ext.LoadMask(this.bwrap,
  564. Ext.apply({}, {store:store}, this.initialConfig.loadMask));
  565. }
  566. this.view.initData(store, colModel);
  567. this.store = store;
  568. this.colModel = colModel;
  569. if(this.rendered){
  570. this.view.refresh(true);
  571. }
  572. this.fireEvent('reconfigure', this, store, colModel);
  573. },
  574. // private
  575. onKeyDown : function(e){
  576. this.fireEvent('keydown', e);
  577. },
  578. // private
  579. onDestroy : function(){
  580. if(this.rendered){
  581. var c = this.body;
  582. c.removeAllListeners();
  583. c.update('');
  584. Ext.destroy(this.view, this.loadMask);
  585. }else if(this.store && this.store.autoDestroy){
  586. this.store.destroy();
  587. }
  588. Ext.destroy(this.colModel, this.selModel);
  589. this.store = this.selModel = this.colModel = this.view = this.loadMask = null;
  590. Ext.grid.GridPanel.superclass.onDestroy.call(this);
  591. },
  592. // private
  593. processEvent : function(name, e){
  594. this.fireEvent(name, e);
  595. var t = e.getTarget();
  596. var v = this.view;
  597. var header = v.findHeaderIndex(t);
  598. if(header !== false){
  599. this.fireEvent('header' + name, this, header, e);
  600. }else{
  601. var row = v.findRowIndex(t);
  602. var cell = v.findCellIndex(t);
  603. if(row !== false){
  604. this.fireEvent('row' + name, this, row, e);
  605. if(cell !== false){
  606. this.fireEvent('cell' + name, this, row, cell, e);
  607. }
  608. }
  609. }
  610. },
  611. // private
  612. onClick : function(e){
  613. this.processEvent('click', e);
  614. },
  615. // private
  616. onMouseDown : function(e){
  617. this.processEvent('mousedown', e);
  618. },
  619. // private
  620. onContextMenu : function(e, t){
  621. this.processEvent('contextmenu', e);
  622. },
  623. // private
  624. onDblClick : function(e){
  625. this.processEvent('dblclick', e);
  626. },
  627. // private
  628. walkCells : function(row, col, step, fn, scope){
  629. var cm = this.colModel, clen = cm.getColumnCount();
  630. var ds = this.store, rlen = ds.getCount(), first = true;
  631. if(step < 0){
  632. if(col < 0){
  633. row--;
  634. first = false;
  635. }
  636. while(row >= 0){
  637. if(!first){
  638. col = clen-1;
  639. }
  640. first = false;
  641. while(col >= 0){
  642. if(fn.call(scope || this, row, col, cm) === true){
  643. return [row, col];
  644. }
  645. col--;
  646. }
  647. row--;
  648. }
  649. } else {
  650. if(col >= clen){
  651. row++;
  652. first = false;
  653. }
  654. while(row < rlen){
  655. if(!first){
  656. col = 0;
  657. }
  658. first = false;
  659. while(col < clen){
  660. if(fn.call(scope || this, row, col, cm) === true){
  661. return [row, col];
  662. }
  663. col++;
  664. }
  665. row++;
  666. }
  667. }
  668. return null;
  669. },
  670. // private
  671. onResize : function(){
  672. Ext.grid.GridPanel.superclass.onResize.apply(this, arguments);
  673. if(this.viewReady){
  674. this.view.layout();
  675. }
  676. },
  677. /**
  678. * Returns the grid's underlying element.
  679. * @return {Element} The element
  680. */
  681. getGridEl : function(){
  682. return this.body;
  683. },
  684. // private for compatibility, overridden by editor grid
  685. stopEditing : Ext.emptyFn,
  686. /**
  687. * Returns the grid's selection model configured by the <code>{@link #selModel}</code>
  688. * configuration option. If no selection model was configured, this will create
  689. * and return a {@link Ext.grid.RowSelectionModel RowSelectionModel}.
  690. * @return {SelectionModel}
  691. */
  692. getSelectionModel : function(){
  693. if(!this.selModel){
  694. this.selModel = new Ext.grid.RowSelectionModel(
  695. this.disableSelection ? {selectRow: Ext.emptyFn} : null);
  696. }
  697. return this.selModel;
  698. },
  699. /**
  700. * Returns the grid's data store.
  701. * @return {Ext.data.Store} The store
  702. */
  703. getStore : function(){
  704. return this.store;
  705. },
  706. /**
  707. * Returns the grid's ColumnModel.
  708. * @return {Ext.grid.ColumnModel} The column model
  709. */
  710. getColumnModel : function(){
  711. return this.colModel;
  712. },
  713. /**
  714. * Returns the grid's GridView object.
  715. * @return {Ext.grid.GridView} The grid view
  716. */
  717. getView : function(){
  718. if(!this.view){
  719. this.view = new Ext.grid.GridView(this.viewConfig);
  720. }
  721. return this.view;
  722. },
  723. /**
  724. * Called to get grid's drag proxy text, by default returns this.ddText.
  725. * @return {String} The text
  726. */
  727. getDragDropText : function(){
  728. var count = this.selModel.getCount();
  729. return String.format(this.ddText, count, count == 1 ? '' : 's');
  730. }
  731. /**
  732. * @cfg {String/Number} activeItem
  733. * @hide
  734. */
  735. /**
  736. * @cfg {Boolean} autoDestroy
  737. * @hide
  738. */
  739. /**
  740. * @cfg {Object/String/Function} autoLoad
  741. * @hide
  742. */
  743. /**
  744. * @cfg {Boolean} autoWidth
  745. * @hide
  746. */
  747. /**
  748. * @cfg {Boolean/Number} bufferResize
  749. * @hide
  750. */
  751. /**
  752. * @cfg {String} defaultType
  753. * @hide
  754. */
  755. /**
  756. * @cfg {Object} defaults
  757. * @hide
  758. */
  759. /**
  760. * @cfg {Boolean} hideBorders
  761. * @hide
  762. */
  763. /**
  764. * @cfg {Mixed} items
  765. * @hide
  766. */
  767. /**
  768. * @cfg {String} layout
  769. * @hide
  770. */
  771. /**
  772. * @cfg {Object} layoutConfig
  773. * @hide
  774. */
  775. /**
  776. * @cfg {Boolean} monitorResize
  777. * @hide
  778. */
  779. /**
  780. * @property items
  781. * @hide
  782. */
  783. /**
  784. * @method add
  785. * @hide
  786. */
  787. /**
  788. * @method cascade
  789. * @hide
  790. */
  791. /**
  792. * @method doLayout
  793. * @hide
  794. */
  795. /**
  796. * @method find
  797. * @hide
  798. */
  799. /**
  800. * @method findBy
  801. * @hide
  802. */
  803. /**
  804. * @method findById
  805. * @hide
  806. */
  807. /**
  808. * @method findByType
  809. * @hide
  810. */
  811. /**
  812. * @method getComponent
  813. * @hide
  814. */
  815. /**
  816. * @method getLayout
  817. * @hide
  818. */
  819. /**
  820. * @method getUpdater
  821. * @hide
  822. */
  823. /**
  824. * @method insert
  825. * @hide
  826. */
  827. /**
  828. * @method load
  829. * @hide
  830. */
  831. /**
  832. * @method remove
  833. * @hide
  834. */
  835. /**
  836. * @event add
  837. * @hide
  838. */
  839. /**
  840. * @event afterLayout
  841. * @hide
  842. */
  843. /**
  844. * @event beforeadd
  845. * @hide
  846. */
  847. /**
  848. * @event beforeremove
  849. * @hide
  850. */
  851. /**
  852. * @event remove
  853. * @hide
  854. */
  855. /**
  856. * @cfg {String} allowDomMove @hide
  857. */
  858. /**
  859. * @cfg {String} autoEl @hide
  860. */
  861. /**
  862. * @cfg {String} applyTo @hide
  863. */
  864. /**
  865. * @cfg {String} autoScroll @hide
  866. */
  867. /**
  868. * @cfg {String} bodyBorder @hide
  869. */
  870. /**
  871. * @cfg {String} bodyStyle @hide
  872. */
  873. /**
  874. * @cfg {String} contentEl @hide
  875. */
  876. /**
  877. * @cfg {String} disabledClass @hide
  878. */
  879. /**
  880. * @cfg {String} elements @hide
  881. */
  882. /**
  883. * @cfg {String} html @hide
  884. */
  885. /**
  886. * @cfg {Boolean} preventBodyReset
  887. * @hide
  888. */
  889. /**
  890. * @property disabled
  891. * @hide
  892. */
  893. /**
  894. * @method applyToMarkup
  895. * @hide
  896. */
  897. /**
  898. * @method enable
  899. * @hide
  900. */
  901. /**
  902. * @method disable
  903. * @hide
  904. */
  905. /**
  906. * @method setDisabled
  907. * @hide
  908. */
  909. });
  910. Ext.reg('grid', Ext.grid.GridPanel);