/*
* Ext JS Library 1.0.1
* Copyright(c) 2006-2007, Ext JS, LLC.
* licensing@extjs.com
*
* http://www.extjs.com/license
*/
/**
* @class Ext.grid.Grid
* @extends Ext.util.Observable
* This class represents the primary interface of a component based grid control.
*
Usage:
var grid = new Ext.grid.Grid("my-container-id", {
ds: myDataStore,
cm: myColModel,
selModel: mySelectionModel,
autoSizeColumns: true,
monitorWindowResize: false,
trackMouseOver: true
});
// set any options
grid.render();
*
* Common Problems:/INPUT|TEXTAREA|SELECT/i).
*/
allowTextSelectionPattern : /INPUT|TEXTAREA|SELECT/i,
/**
* @cfg {Object} An {@link Ext.LoadMask} config or true to mask the grid while loading (defaults to false).
*/
loadMask : false,
// private
rendered : false,
/**
* Sets the maximum height of the grid - ignored if autoHeight is not on.
* @type Number
*/
/**
* Called once after all setup has been completed and the grid is ready to be rendered.
* @return {Ext.grid.Grid} this
*/
render : function(){
var c = this.container;
// try to detect autoHeight/width mode
if((!c.dom.offsetHeight || c.dom.offsetHeight < 20) || c.getStyle("height") == "auto"){
this.autoHeight = true;
}
var view = this.getView();
view.init(this);
c.on("click", this.onClick, this);
c.on("dblclick", this.onDblClick, this);
c.on("contextmenu", this.onContextMenu, this);
c.on("keydown", this.onKeyDown, this);
this.relayEvents(c, ["mousedown","mouseup","mouseover","mouseout","keypress"]);
this.getSelectionModel().init(this);
view.render();
if(this.loadMask){
this.loadMask = new Ext.LoadMask(this.container,
Ext.apply({store:this.dataSource}, this.loadMask));
}
this.rendered = true;
return this;
},
reconfigure : function(dataSource, colModel){
if(this.loadMask){
this.loadMask.destroy();
this.loadMask = new Ext.LoadMask(this.container,
Ext.apply({store:dataSource}, this.loadMask));
}
this.view.bind(dataSource, colModel);
this.dataSource = dataSource;
this.colModel = colModel;
this.view.refresh(true);
},
onKeyDown : function(e){
this.fireEvent("keydown", e);
},
/**
* Destroy this grid.
* @param {Boolean} removeEl True to remove the element
*/
destroy : function(removeEl, keepListeners){
if(this.loadMask){
this.loadMask.destroy();
}
var c = this.container;
c.removeAllListeners();
this.view.destroy();
this.colModel.purgeListeners();
if(!keepListeners){
this.purgeListeners();
}
c.update("");
if(removeEl === true){
c.remove();
}
},
// private
processEvent : function(name, e){
this.fireEvent(name, e);
var t = e.getTarget();
var v = this.view;
var header = v.findHeaderIndex(t);
if(header !== false){
this.fireEvent("header" + name, this, header, e);
}else{
var row = v.findRowIndex(t);
var cell = v.findCellIndex(t);
if(row !== false){
this.fireEvent("row" + name, this, row, e);
if(cell !== false){
this.fireEvent("cell" + name, this, row, cell, e);
}
}
}
},
// private
onClick : function(e){
this.processEvent("click", e);
},
// private
onContextMenu : function(e, t){
this.processEvent("contextmenu", e);
},
// private
onDblClick : function(e){
this.processEvent("dblclick", e);
},
walkCells : function(row, col, step, fn, scope){
var cm = this.colModel, clen = cm.getColumnCount();
var ds = this.dataSource, rlen = ds.getCount(), first = true;
if(step < 0){
if(col < 0){
row--;
first = false;
}
while(row >= 0){
if(!first){
col = clen-1;
}
first = false;
while(col >= 0){
if(fn.call(scope || this, row, col, cm) === true){
return [row, col];
}
col--;
}
row--;
}
} else {
if(col >= clen){
row++;
first = false;
}
while(row < rlen){
if(!first){
col = 0;
}
first = false;
while(col < clen){
if(fn.call(scope || this, row, col, cm) === true){
return [row, col];
}
col++;
}
row++;
}
}
return null;
},
getSelections : function(){
return this.selModel.getSelections();
},
/**
* Causes the grid to manually recalculate its dimensions. Generally this is done automatically,
* but if manual update is required this method will initiate it.
*/
autoSize : function(){
if(this.rendered){
this.view.layout();
if(this.view.adjustForScroll){
this.view.adjustForScroll();
}
}
},
// private for compatibility, overridden by editor grid
stopEditing : function(){},
/**
* Returns the grid's SelectionModel.
* @return {SelectionModel}
*/
getSelectionModel : function(){
if(!this.selModel){
this.selModel = new Ext.grid.RowSelectionModel();
}
return this.selModel;
},
/**
* Returns the grid's DataSource.
* @return {DataSource}
*/
getDataSource : function(){
return this.dataSource;
},
/**
* Returns the grid's ColumnModel.
* @return {ColumnModel}
*/
getColumnModel : function(){
return this.colModel;
},
/**
* Returns the grid's GridView object.
* @return {GridView}
*/
getView : function(){
if(!this.view){
this.view = new Ext.grid.GridView();
}
return this.view;
},
/**
* Called to get grid's drag proxy text, by default returns this.ddText.
* @return {String}
*/
getDragDropText : function(){
var count = this.selModel.getCount();
return String.format(this.ddText, count, count == 1 ? '' : 's');
}
});
/**
* Configures the text is the drag proxy (defaults to "%0 selected row(s)").
* %0 is replaced with the number of selected rows.
* @type String
*/
Ext.grid.Grid.prototype.ddText = "{0} selected row{1}";