2
* Ext JS Library 3.0 RC2
3
* Copyright(c) 2006-2009, Ext JS, LLC.
6
* http://extjs.com/license
10
* @class Ext.grid.GridPanel
12
* <p>This class represents the primary interface of a component based grid control to represent data
13
* in a tabular format of rows and columns. The GridPanel is composed of the following:</p>
14
* <div class="mdetail-params"><ul>
15
* <li><b>{@link Ext.data.Store Store}</b> : The Model holding the data records (rows)
16
* <div class="sub-desc"></div></li>
17
* <li><b>{@link Ext.grid.ColumnModel Column model}</b> : Column makeup
18
* <div class="sub-desc"></div></li>
19
* <li><b>{@link Ext.grid.GridView View}</b> : Encapsulates the user interface
20
* <div class="sub-desc"></div></li>
21
* <li><b>{@link Ext.grid.AbstractSelectionModel selection model}</b> : Selection behavior
22
* <div class="sub-desc"></div></li>
24
* <p>Example usage:</p>
26
var grid = new Ext.grid.GridPanel({
27
{@link #store}: new (@link Ext.data.Store}({
28
{@link Ext.data.Store#autoDestroy autoDestroy}: true,
29
{@link Ext.data.Store#reader reader}: reader,
30
{@link Ext.data.Store#data data}: xg.dummyData
33
{id: 'company', header: 'Company', width: 200, sortable: true, dataIndex: 'company'},
34
{header: 'Price', width: 120, sortable: true, renderer: Ext.util.Format.usMoney, dataIndex: 'price'},
35
{header: 'Change', width: 120, sortable: true, dataIndex: 'change'},
36
{header: '% Change', width: 120, sortable: true, dataIndex: 'pctChange'},
37
// instead of specifying renderer: Ext.util.Format.dateRenderer('m/d/Y') use xtype
38
{header: 'Last Updated', width: 135, sortable: true, dataIndex: 'lastChange', xtype: 'datecolumn', format: 'M d, Y'}
40
{@link #viewConfig}: {
41
{@link Ext.grid.GridView#forceFit forceFit}: true,
43
// Return CSS class to apply to rows depending upon data values
44
{@link Ext.grid.GridView#getRowClass getRowClass}: function(record, index) {
45
var c = record.{@link Ext.data.Record#get get}('change');
53
{@link #sm}: new Ext.grid.RowSelectionModel({singleSelect:true}),
57
title: 'Framed with Row Selection and Horizontal Scrolling',
61
* <p><b><u>Notes:</u></b></p>
62
* <div class="mdetail-params"><ul>
63
* <li>Although this class inherits many configuration options from base classes, some of them
64
* (such as autoScroll, autoWidth, layout, items, etc) are not used by this class, and will
65
* have no effect.</li>
66
* <li>A grid <b>requires</b> a width in which to scroll its columns, and a height in which to
67
* scroll its rows. These dimensions can either be set explicitly through the
68
* <tt>{@link Ext.BoxComponent#height height}</tt> and <tt>{@link Ext.BoxComponent#width width}</tt>
69
* configuration options or implicitly set by using the grid as a child item of a
70
* {@link Ext.Container Container} which will have a {@link Ext.Container#layout layout manager}
71
* provide the sizing of its child items (for example the Container of the Grid may specify
72
* <tt>{@link Ext.Container#layout layout}:'fit'</tt>).</li>
73
* <li>To access the data in a Grid, it is necessary to use the data model encapsulated
74
* by the {@link #store Store}. See the {@link #cellclick} event for more details.</li>
77
* @param {Object} config The config object
80
Ext.grid.GridPanel = Ext.extend(Ext.Panel, {
82
* @cfg {String} autoExpandColumn
83
* <p>The <tt>{@link Ext.grid.Column#id id}</tt> of a {@link Ext.grid.Column column} in
84
* this grid that should expand to fill unused space. This value specified here can not
86
* <br><p><b>Note</b>: If the Grid's {@link Ext.grid.GridView view} is configured with
87
* <tt>{@link Ext.grid.GridView#forceFit forceFit}=true</tt> the <tt>autoExpandColumn</tt>
88
* is ignored. See {@link Ext.grid.Column}.<tt>{@link Ext.grid.Column#width width}</tt>
89
* for additional details.</p>
90
* <p>See <tt>{@link #autoExpandMax}</tt> and <tt>{@link #autoExpandMin}</tt> also.</p>
92
autoExpandColumn : false,
94
* @cfg {Number} autoExpandMax The maximum width the <tt>{@link #autoExpandColumn}</tt>
95
* can have (if enabled). Defaults to <tt>1000</tt>.
99
* @cfg {Number} autoExpandMin The minimum width the <tt>{@link #autoExpandColumn}</tt>
100
* can have (if enabled). Defaults to <tt>50</tt>.
104
* @cfg {Boolean} columnLines <tt>true</tt> to add css for column separation lines.
105
* Default is <tt>false</tt>.
109
* @cfg {Object} cm Shorthand for <tt>{@link #colModel}</tt>.
112
* @cfg {Object} colModel The {@link Ext.grid.ColumnModel} to use when rendering the grid (required).
115
* @cfg {Array} columns An array of {@link Ext.grid.Column columns} to auto create a
116
* {@link Ext.grid.ColumnModel}. The ColumnModel may be explicitly created via the
117
* <tt>{@link #colModel}</tt> configuration property.
120
* @cfg {String} ddText
121
* Configures the text in the drag proxy. Defaults to:
123
* ddText : "{0} selected row{1}"
125
* <tt>{0}</tt> is replaced with the number of selected rows.
127
ddText : "{0} selected row{1}",
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>
133
deferRowRender : true,
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>
139
* @cfg {Boolean} enableColumnResize <tt>false</tt> to turn off column resizing for the whole grid. Defaults to <tt>true</tt>.
142
* @cfg {Boolean} enableColumnHide Defaults to <tt>true</tt> to enable hiding of columns with the header context menu.
144
enableColumnHide : true,
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.
149
enableColumnMove : true,
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>
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>
161
enableDragDrop : false,
163
* @cfg {Boolean} enableHdMenu Defaults to <tt>true</tt> to enable the drop down button for menu in the headers.
167
* @cfg {Boolean} hideHeaders True to hide the grid's header. Defaults to <code>false</code>.
170
* @cfg {Object} loadMask An {@link Ext.LoadMask} config or true to mask the grid while
171
* loading. Defaults to <code>false</code>.
175
* @cfg {Number} maxHeight Sets the maximum height of the grid - ignored if <tt>autoHeight</tt> is not on.
178
* @cfg {Number} minColumnWidth The minimum width a column can be resized to. Defaults to <tt>25</tt>.
182
* @cfg {Object} sm Shorthand for <tt>{@link #selModel}</tt>.
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).
189
* @cfg {Ext.data.Store} store The {@link Ext.data.Store} the grid should use as its data source (required).
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>
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.
203
trackMouseOver : true,
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"]
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>
215
stateEvents : ["columnmove", "columnresize", "sortchange"],
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()}.
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.
233
initComponent : function(){
234
Ext.grid.GridPanel.superclass.initComponent.call(this);
236
if(this.columnLines){
237
this.cls = (this.cls || '') + ' x-grid-with-col-lines';
239
// override any provided value since it isn't valid
240
// and is causing too many bug reports ;)
241
this.autoScroll = false;
242
this.autoWidth = false;
244
if(Ext.isArray(this.columns)){
245
this.colModel = new Ext.grid.ColumnModel(this.columns);
249
// check and correct shorthanded configs
251
this.store = this.ds;
255
this.colModel = this.cm;
259
this.selModel = this.sm;
262
this.store = Ext.StoreMgr.lookup(this.store);
268
* The raw click event for the entire grid.
269
* @param {Ext.EventObject} e
274
* The raw dblclick event for the entire grid.
275
* @param {Ext.EventObject} e
280
* The raw contextmenu event for the entire grid.
281
* @param {Ext.EventObject} e
286
* The raw mousedown event for the entire grid.
287
* @param {Ext.EventObject} e
292
* The raw mouseup event for the entire grid.
293
* @param {Ext.EventObject} e
298
* The raw mouseover event for the entire grid.
299
* @param {Ext.EventObject} e
304
* The raw mouseout event for the entire grid.
305
* @param {Ext.EventObject} e
310
* The raw keypress event for the entire grid.
311
* @param {Ext.EventObject} e
316
* The raw keydown event for the entire grid.
317
* @param {Ext.EventObject} e
323
* @event cellmousedown
324
* Fires before a cell is clicked
326
* @param {Number} rowIndex
327
* @param {Number} columnIndex
328
* @param {Ext.EventObject} e
332
* @event rowmousedown
333
* Fires before a row is clicked
335
* @param {Number} rowIndex
336
* @param {Ext.EventObject} e
340
* @event headermousedown
341
* Fires before a header is clicked
343
* @param {Number} columnIndex
344
* @param {Ext.EventObject} e
350
* Fires when a cell is clicked.
351
* The data for the cell is drawn from the {@link Ext.data.Record Record}
352
* for this row. To access the data in the listener function use the
353
* following technique:
355
function(grid, rowIndex, columnIndex, e) {
356
var record = grid.getStore().getAt(rowIndex); // Get the Record
357
var fieldName = grid.getColumnModel().getDataIndex(columnIndex); // Get field name
358
var data = record.get(fieldName);
362
* @param {Number} rowIndex
363
* @param {Number} columnIndex
364
* @param {Ext.EventObject} e
368
* @event celldblclick
369
* Fires when a cell is double clicked
371
* @param {Number} rowIndex
372
* @param {Number} columnIndex
373
* @param {Ext.EventObject} e
378
* Fires when a row is clicked
380
* @param {Number} rowIndex
381
* @param {Ext.EventObject} e
386
* Fires when a row is double clicked
388
* @param {Number} rowIndex
389
* @param {Ext.EventObject} e
394
* Fires when a header is clicked
396
* @param {Number} columnIndex
397
* @param {Ext.EventObject} e
401
* @event headerdblclick
402
* Fires when a header cell is double clicked
404
* @param {Number} columnIndex
405
* @param {Ext.EventObject} e
409
* @event rowcontextmenu
410
* Fires when a row is right clicked
412
* @param {Number} rowIndex
413
* @param {Ext.EventObject} e
417
* @event cellcontextmenu
418
* Fires when a cell is right clicked
420
* @param {Number} rowIndex
421
* @param {Number} cellIndex
422
* @param {Ext.EventObject} e
426
* @event headercontextmenu
427
* Fires when a header is right clicked
429
* @param {Number} columnIndex
430
* @param {Ext.EventObject} e
435
* Fires when the body element is scrolled
436
* @param {Number} scrollLeft
437
* @param {Number} scrollTop
441
* @event columnresize
442
* Fires when the user resizes a column
443
* @param {Number} columnIndex
444
* @param {Number} newSize
449
* Fires when the user moves a column
450
* @param {Number} oldIndex
451
* @param {Number} newIndex
456
* Fires when the grid's store sort changes
458
* @param {Object} sortInfo An object with the keys field and direction
465
onRender : function(ct, position){
466
Ext.grid.GridPanel.superclass.onRender.apply(this, arguments);
470
this.el.addClass('x-grid-panel');
472
var view = this.getView();
476
mousedown: this.onMouseDown,
478
dblclick: this.onDblClick,
479
contextmenu: this.onContextMenu,
480
keydown: this.onKeyDown,
484
this.relayEvents(c, ["mousedown","mouseup","mouseover","mouseout","keypress"]);
486
this.getSelectionModel().init(this);
491
initEvents : function(){
492
Ext.grid.GridPanel.superclass.initEvents.call(this);
495
this.loadMask = new Ext.LoadMask(this.bwrap,
496
Ext.apply({store:this.store}, this.loadMask));
500
initStateEvents : function(){
501
Ext.grid.GridPanel.superclass.initStateEvents.call(this);
502
this.mon(this.colModel, 'hiddenchange', this.saveState, this, {delay: 100});
505
applyState : function(state){
506
var cm = this.colModel;
507
var cs = state.columns;
509
for(var i = 0, len = cs.length; i < len; i++){
511
var c = cm.getColumnById(s.id);
515
var oldIndex = cm.getIndexById(s.id);
517
cm.moveColumn(oldIndex, i);
522
if(state.sort && this.store){
523
this.store[this.store.remoteSort ? 'setDefaultSort' : 'sort'](state.sort.field, state.sort.direction);
525
delete state.columns;
527
Ext.grid.GridPanel.superclass.applyState.call(this, state);
530
getState : function(){
531
var o = {columns: []};
532
for(var i = 0, c; c = this.colModel.config[i]; i++){
538
o.columns[i].hidden = true;
542
var ss = this.store.getSortState();
551
afterRender : function(){
552
Ext.grid.GridPanel.superclass.afterRender.call(this);
554
if(this.deferRowRender){
555
this.view.afterRender.defer(10, this.view);
557
this.view.afterRender();
559
this.viewReady = true;
563
* <p>Reconfigures the grid to use a different Store and Column Model.
564
* The View will be bound to the new objects and refreshed.</p>
565
* <p>Be aware that upon reconfiguring a GridPanel, certain existing settings <i>may</i> become
566
* invalidated. For example the configured {@link #autoExpandColumn} may no longer exist in the
567
* new ColumnModel. Also, an existing {@link Ext.PagingToolbar PagingToolbar} will still be bound
568
* to the old Store, and will need rebinding. Any {@link #plugins} might also need reconfiguring
569
* with the new data.</p>
570
* @param {Ext.data.Store} store The new {@link Ext.data.Store} object
571
* @param {Ext.grid.ColumnModel} colModel The new {@link Ext.grid.ColumnModel} object
573
reconfigure : function(store, colModel){
575
this.loadMask.destroy();
576
this.loadMask = new Ext.LoadMask(this.bwrap,
577
Ext.apply({}, {store:store}, this.initialConfig.loadMask));
579
this.view.initData(store, colModel);
581
this.colModel = colModel;
583
this.view.refresh(true);
588
onKeyDown : function(e){
589
this.fireEvent("keydown", e);
593
onDestroy : function(){
596
c.removeAllListeners();
598
Ext.destroy(this.view, this.loadMask);
599
}else if(this.store && this.store.autoDestroy){
600
this.store.destroy();
602
Ext.destroy(this.colModel);
603
this.store = this.colModel = this.view = this.loadMask = null;
604
Ext.grid.GridPanel.superclass.onDestroy.call(this);
608
processEvent : function(name, e){
609
this.fireEvent(name, e);
610
var t = e.getTarget();
612
var header = v.findHeaderIndex(t);
613
if(header !== false){
614
this.fireEvent("header" + name, this, header, e);
616
var row = v.findRowIndex(t);
617
var cell = v.findCellIndex(t);
619
this.fireEvent("row" + name, this, row, e);
621
this.fireEvent("cell" + name, this, row, cell, e);
628
onClick : function(e){
629
this.processEvent("click", e);
633
onMouseDown : function(e){
634
this.processEvent("mousedown", e);
638
onContextMenu : function(e, t){
639
this.processEvent("contextmenu", e);
643
onDblClick : function(e){
644
this.processEvent("dblclick", e);
648
walkCells : function(row, col, step, fn, scope){
649
var cm = this.colModel, clen = cm.getColumnCount();
650
var ds = this.store, rlen = ds.getCount(), first = true;
662
if(fn.call(scope || this, row, col, cm) === true){
680
if(fn.call(scope || this, row, col, cm) === true){
692
onResize : function(){
693
Ext.grid.GridPanel.superclass.onResize.apply(this, arguments);
700
* Returns the grid's underlying element.
701
* @return {Element} The element
703
getGridEl : function(){
707
// private for compatibility, overridden by editor grid
708
stopEditing : Ext.emptyFn,
711
* Returns the grid's SelectionModel.
712
* @return {SelectionModel} The selection model configured by the @link (#selModel} configuration option.
713
* This will be a subclass of {@link Ext.grid.AbstractSelectionModel} which provides either cell or row
714
* selectability. If no selection model was configured, this will return a {@link Ext.grid.RowSelectionModel RowSelectionModel}.
716
getSelectionModel : function(){
718
this.selModel = new Ext.grid.RowSelectionModel(
719
this.disableSelection ? {selectRow: Ext.emptyFn} : null);
721
return this.selModel;
725
* Returns the grid's data store.
726
* @return {Ext.data.Store} The store
728
getStore : function(){
733
* Returns the grid's ColumnModel.
734
* @return {Ext.grid.ColumnModel} The column model
736
getColumnModel : function(){
737
return this.colModel;
741
* Returns the grid's GridView object.
742
* @return {Ext.grid.GridView} The grid view
744
getView : function(){
746
this.view = new Ext.grid.GridView(this.viewConfig);
751
* Called to get grid's drag proxy text, by default returns this.ddText.
752
* @return {String} The text
754
getDragDropText : function(){
755
var count = this.selModel.getCount();
756
return String.format(this.ddText, count, count == 1 ? '' : 's');
760
* @cfg {String/Number} activeItem
764
* @cfg {Boolean} autoDestroy
768
* @cfg {Object/String/Function} autoLoad
772
* @cfg {Boolean} autoWidth
776
* @cfg {Boolean/Number} bufferResize
780
* @cfg {String} defaultType
784
* @cfg {Object} defaults
788
* @cfg {Boolean} hideBorders
796
* @cfg {String} layout
800
* @cfg {Object} layoutConfig
804
* @cfg {Boolean} monitorResize
840
* @method getComponent
876
* @event beforeremove
887
* @cfg {String} allowDomMove @hide
890
* @cfg {String} autoEl @hide
893
* @cfg {String} applyTo @hide
896
* @cfg {String} autoScroll @hide
899
* @cfg {String} bodyBorder @hide
902
* @cfg {String} bodyStyle @hide
905
* @cfg {String} contentEl @hide
908
* @cfg {String} disabledClass @hide
911
* @cfg {String} elements @hide
914
* @cfg {String} html @hide
921
* @method applyToMarkup
933
* @method setDisabled
937
Ext.reg('grid', Ext.grid.GridPanel);
b'\\ No newline at end of file'