webgui/www/extras/yui-ext/docs/overview-summary-Grid.js.html
JT Smith 4f68a0933c added YUI and YUI-ext
fixed the resizable text area with IE problem
fixed the ad space with IE problem
merged the 7.2.0 and 7.1.4 change logs
2006-11-07 23:15:57 +00:00

789 lines
43 KiB
HTML

<!doctype html public "-//W3C//DTD HTML 4.0 Frameset//EN""http://www.w3.org/TR/REC-html40/frameset.dtd">
<html>
<head>
<title>
Overview
</title>
<link rel ="stylesheet" type="text/css" href="stylesheet.css" title="Style">
<script>
function asd() {
parent.document.title="Grid.js Overview";
}
</script>
</head>
<body bgcolor="white" onload="asd();" style="margin:15px;">
<center>
<h2>Grid.js</h2>
</center>
<h4>Summary</h4>
<p>
</p>
<table border="1" cellpadding="3" cellspacing="0" width="100%">
<tr bgcolor="#CCCCFF" class="TableHeadingColor">
<td colspan="2" class="title-cell">
<b>Class Summary</b>
</td>
</tr>
<tr bgcolor="white" class="TableRowColor">
<td width="15%"><b><a href="YAHOO.ext.grid.Grid.html">YAHOO.ext.grid.Grid</a></b></td>
<td>This class represents the primary interface of a component based grid control.</td>
</tr>
</table>
<hr/>
<!-- ========== METHOD SUMMARY =========== -->
<!-- ========== END METHOD SUMMARY =========== -->
<pre class="sourceview">YAHOO.namespace(<span class="literal">'ext.grid'</span>);
<span class="comment">/**
* <span class="attrib">@class</span>
* This class represents the primary interface of a component based grid control.
* &lt;br&gt;&lt;br&gt;Usage:&lt;pre&gt;&lt;code&gt;
* var grid = new YAHOO.ext.grid.Grid('my-container-id', dataModel, columnModel);
* // set any options
* grid.render();
* &lt;/code&gt;&lt;/pre&gt;
* <span class="attrib">@requires</span> YAHOO.util.Dom
* <span class="attrib">@requires</span> YAHOO.util.Event
* <span class="attrib">@requires</span> YAHOO.util.CustomEvent
* <span class="attrib">@requires</span> YAHOO.ext.Element
* <span class="attrib">@requires</span> YAHOO.ext.util.Browser
* <span class="attrib">@requires</span> YAHOO.ext.util.CSS
* <span class="attrib">@requires</span> YAHOO.ext.SplitBar
* <span class="attrib">@requires</span> YAHOO.ext.EventObject
* <span class="attrib">@constructor</span>
* <span class="attrib">@param</span> {String/HTMLElement/YAHOO.ext.Element} container The element into which this grid will be rendered -
* The container MUST have some type of size defined for the grid to fill. The container will be
* automatically set to position relative if it isn't already.
* <span class="attrib">@param</span> {Object} dataModel The data model to bind to
* <span class="attrib">@param</span> {Object} colModel The column model with info about this grid's columns
* <span class="attrib">@param</span> {&lt;i&gt;Object&lt;/i&gt;} selectionModel (optional) The selection model for this grid (defaults to DefaultSelectionModel)
*/</span>
YAHOO.ext.grid.Grid = <span class="reserved">function</span>(container, dataModel, colModel, selectionModel){
<span class="comment">/** <span class="attrib">@private</span> */</span>
<span class="reserved">this</span>.container = YAHOO.ext.Element.get(container);
<span class="reserved">if</span>(<span class="reserved">this</span>.container.getStyle(<span class="literal">'position'</span>) != <span class="literal">'absolute'</span>){
<span class="reserved">this</span>.container.setStyle(<span class="literal">'position'</span>, <span class="literal">'relative'</span>);
}
<span class="comment">/** <span class="attrib">@private</span> */</span>
<span class="reserved">this</span>.id = <span class="reserved">this</span>.container.id;
<span class="comment">/** <span class="attrib">@private</span> */</span>
<span class="reserved">this</span>.rows = [];
<span class="comment">/** <span class="attrib">@private</span> */</span>
<span class="reserved">this</span>.rowCount = 0;
<span class="comment">/** <span class="attrib">@private</span> */</span>
<span class="reserved">this</span>.fieldId = null;
<span class="comment">/** <span class="attrib">@private</span> */</span>
<span class="reserved">this</span>.dataModel = dataModel;
<span class="comment">/** <span class="attrib">@private</span> */</span>
<span class="reserved">this</span>.colModel = colModel;
<span class="comment">/** <span class="attrib">@private</span> */</span>
<span class="reserved">this</span>.selModel = selectionModel;
<span class="comment">/** <span class="attrib">@private</span> */</span>
<span class="reserved">this</span>.activeEditor = null;
<span class="comment">/** <span class="attrib">@private</span> */</span>
<span class="reserved">this</span>.editingCell = null;
<span class="comment">/** The minimum width a column can be resized to. (Defaults to 25)
* <span class="attrib">@type</span> Number */</span>
<span class="reserved">this</span>.minColumnWidth = 25;
<span class="comment">/** True to automatically resize the columns to fit their content &lt;b&gt;on initial render&lt;/b&gt;
* <span class="attrib">@type</span> Boolean */</span>
<span class="reserved">this</span>.autoSizeColumns = false;
<span class="comment">/** True to measure headers with column data when auto sizing columns
* <span class="attrib">@type</span> Boolean */</span>
<span class="reserved">this</span>.autoSizeHeaders = false;
<span class="comment">/** If autoSizeColumns is on, maxRowsToMeasure can be used to limit the number of
* rows measured to get a columns size - defaults to 0 (all rows).
* <span class="attrib">@type</span> Number */</span>
<span class="reserved">this</span>.maxRowsToMeasure = 0;
<span class="comment">/** True to highlight rows when the mouse is over (default is false)
* <span class="attrib">@type</span> Boolean */</span>
<span class="reserved">this</span>.trackMouseOver = false;
<span class="comment">/** True to enable drag and drop of rows
* <span class="attrib">@type</span> Boolean */</span>
<span class="reserved">this</span>.enableDragDrop = false;
<span class="comment">/** True to stripe the rows (default is true)
* <span class="attrib">@type</span> Boolean */</span>
<span class="reserved">this</span>.stripeRows = true;
<span class="comment">/** A regular expression defining tagNames
* allowed to have text selection (Defaults to &lt;code&gt;/INPUT|TEXTAREA/i&lt;/code&gt;) */</span>
<span class="reserved">this</span>.allowTextSelectionPattern = /INPUT|TEXTAREA|SELECT/i;
<span class="comment">/** <span class="attrib">@private</span> */</span>
<span class="reserved">this</span>.setValueDelegate = <span class="reserved">this</span>.setCellValue.createDelegate(<span class="reserved">this</span>);
var CE = YAHOO.util.CustomEvent;
<span class="comment">/** <span class="attrib">@private</span> */</span>
<span class="reserved">this</span>.events = {
<span class="comment">// raw events</span>
<span class="literal">'click'</span> : new CE(<span class="literal">'click'</span>),
<span class="literal">'dblclick'</span> : new CE(<span class="literal">'dblclick'</span>),
<span class="literal">'mousedown'</span> : new CE(<span class="literal">'mousedown'</span>),
<span class="literal">'mouseup'</span> : new CE(<span class="literal">'mouseup'</span>),
<span class="literal">'mouseover'</span> : new CE(<span class="literal">'mouseover'</span>),
<span class="literal">'mouseout'</span> : new CE(<span class="literal">'mouseout'</span>),
<span class="literal">'keypress'</span> : new CE(<span class="literal">'keypress'</span>),
<span class="literal">'keydown'</span> : new CE(<span class="literal">'keydown'</span>),
<span class="comment">// custom events</span>
<span class="literal">'cellclick'</span> : new CE(<span class="literal">'cellclick'</span>),
<span class="literal">'celldblclick'</span> : new CE(<span class="literal">'celldblclick'</span>),
<span class="literal">'rowclick'</span> : new CE(<span class="literal">'rowclick'</span>),
<span class="literal">'rowdblclick'</span> : new CE(<span class="literal">'rowdblclick'</span>),
<span class="literal">'headerclick'</span> : new CE(<span class="literal">'headerclick'</span>),
<span class="literal">'rowcontextmenu'</span> : new CE(<span class="literal">'rowcontextmenu'</span>),
<span class="literal">'headercontextmenu'</span> : new CE(<span class="literal">'headercontextmenu'</span>),
<span class="literal">'beforeedit'</span> : new CE(<span class="literal">'beforeedit'</span>),
<span class="literal">'afteredit'</span> : new CE(<span class="literal">'afteredit'</span>),
<span class="literal">'bodyscroll'</span> : new CE(<span class="literal">'bodyscroll'</span>),
<span class="literal">'columnresize'</span> : new CE(<span class="literal">'columnresize'</span>),
<span class="literal">'startdrag'</span> : new CE(<span class="literal">'startdrag'</span>),
<span class="literal">'enddrag'</span> : new CE(<span class="literal">'enddrag'</span>),
<span class="literal">'dragdrop'</span> : new CE(<span class="literal">'dragdrop'</span>),
<span class="literal">'dragover'</span> : new CE(<span class="literal">'dragover'</span>),
<span class="literal">'dragenter'</span> : new CE(<span class="literal">'dragenter'</span>),
<span class="literal">'dragout'</span> : new CE(<span class="literal">'dragout'</span>)
};
};
YAHOO.ext.grid.Grid.<span class="reserved">prototype</span> = {
<span class="comment">/**
* Called once after all setup has been completed and the grid is ready to be rendered.
*/</span>
render : <span class="reserved">function</span>(){
<span class="reserved">if</span>(!<span class="reserved">this</span>.view){
<span class="reserved">if</span>(<span class="reserved">this</span>.dataModel.isPaged()){
<span class="reserved">this</span>.view = new YAHOO.ext.grid.PagedGridView();
}<span class="reserved">else</span>{
<span class="reserved">this</span>.view = new YAHOO.ext.grid.GridView();
}
}
<span class="reserved">this</span>.view.init(<span class="reserved">this</span>);
<span class="reserved">this</span>.el = getEl(<span class="reserved">this</span>.view.render(), true);
var c = <span class="reserved">this</span>.container;
c.mon(<span class="literal">"click"</span>, <span class="reserved">this</span>.onClick, <span class="reserved">this</span>, true);
c.mon(<span class="literal">"dblclick"</span>, <span class="reserved">this</span>.onDblClick, <span class="reserved">this</span>, true);
c.mon(<span class="literal">"contextmenu"</span>, <span class="reserved">this</span>.onContextMenu, <span class="reserved">this</span>, true);
c.mon(<span class="literal">"selectstart"</span>, <span class="reserved">this</span>.cancelTextSelection, <span class="reserved">this</span>, true);
c.mon(<span class="literal">"mousedown"</span>, <span class="reserved">this</span>.cancelTextSelection, <span class="reserved">this</span>, true);
c.mon(<span class="literal">"mousedown"</span>, <span class="reserved">this</span>.onMouseDown, <span class="reserved">this</span>, true);
c.mon(<span class="literal">"mouseup"</span>, <span class="reserved">this</span>.onMouseUp, <span class="reserved">this</span>, true);
<span class="reserved">if</span>(<span class="reserved">this</span>.trackMouseOver){
<span class="reserved">this</span>.el.mon(<span class="literal">"mouseover"</span>, <span class="reserved">this</span>.onMouseOver, <span class="reserved">this</span>, true);
<span class="reserved">this</span>.el.mon(<span class="literal">"mouseout"</span>, <span class="reserved">this</span>.onMouseOut, <span class="reserved">this</span>, true);
}
c.mon(<span class="literal">"keypress"</span>, <span class="reserved">this</span>.onKeyPress, <span class="reserved">this</span>, true);
c.mon(<span class="literal">"keydown"</span>, <span class="reserved">this</span>.onKeyDown, <span class="reserved">this</span>, true);
<span class="reserved">this</span>.init();
},
<span class="comment">/** <span class="attrib">@private</span> */</span>
init : <span class="reserved">function</span>(){
<span class="reserved">this</span>.rows = <span class="reserved">this</span>.el.dom.rows;
<span class="reserved">if</span>(!<span class="reserved">this</span>.disableSelection){
<span class="reserved">if</span>(!<span class="reserved">this</span>.selModel){
<span class="reserved">this</span>.selModel = new YAHOO.ext.grid.DefaultSelectionModel(<span class="reserved">this</span>);
}
<span class="reserved">this</span>.selModel.init(<span class="reserved">this</span>);
<span class="reserved">this</span>.selModel.onSelectionChange.subscribe(<span class="reserved">this</span>.updateField, <span class="reserved">this</span>, true);
}<span class="reserved">else</span>{
<span class="reserved">this</span>.selModel = new YAHOO.ext.grid.DisableSelectionModel(<span class="reserved">this</span>);
<span class="reserved">this</span>.selModel.init(<span class="reserved">this</span>);
}
<span class="reserved">if</span>(<span class="reserved">this</span>.enableDragDrop){
<span class="reserved">this</span>.dd = new YAHOO.ext.grid.GridDD(<span class="reserved">this</span>, <span class="reserved">this</span>.container.dom);
}
},
<span class="comment">/** <span class="attrib">@ignore</span> */</span>
onMouseDown : <span class="reserved">function</span>(e){
<span class="reserved">this</span>.fireEvent(<span class="literal">'mousedown'</span>, e);
},
<span class="comment">/** <span class="attrib">@ignore</span> */</span>
onMouseUp : <span class="reserved">function</span>(e){
<span class="reserved">this</span>.fireEvent(<span class="literal">'mouseup'</span>, e);
},
<span class="comment">/** <span class="attrib">@ignore</span> */</span>
onMouseOver : <span class="reserved">function</span>(e){
<span class="reserved">this</span>.fireEvent(<span class="literal">'mouseover'</span>, e);
},
<span class="comment">/** <span class="attrib">@ignore</span> */</span>
onMouseOut : <span class="reserved">function</span>(e){
<span class="reserved">this</span>.fireEvent(<span class="literal">'mouseout'</span>, e);
},
<span class="comment">/** <span class="attrib">@ignore</span> */</span>
onKeyPress : <span class="reserved">function</span>(e){
<span class="reserved">this</span>.fireEvent(<span class="literal">'keypress'</span>, e);
},
<span class="comment">/** <span class="attrib">@ignore</span> */</span>
onKeyDown : <span class="reserved">function</span>(e){
<span class="reserved">this</span>.fireEvent(<span class="literal">'keydown'</span>, e);
},
<span class="comment">/**
* <span class="attrib">@private</span> internal event firing
* expects arguments[0] is the event name and the rest are the fireDirect arguments
*/</span>
fireEvent : <span class="reserved">function</span>(){
var ce = <span class="reserved">this</span>.events[arguments[0].toLowerCase()];
ce.fireDirect.apply(ce, Array.<span class="reserved">prototype</span>.slice.call(arguments, 1));
},
<span class="comment">/**
* Adds a listener for one of the many defined grid events
* <span class="attrib">@param</span> {String} eventName The type of event to listen for
* <span class="attrib">@param</span> {Function} fn The method the event invokes
* <span class="attrib">@param</span> {&lt;i&gt;Object&lt;/i&gt;} scope (optional) An arbitrary object that will be
* passed as a parameter to the handler
* <span class="attrib">@param</span> {&lt;i&gt;boolean&lt;/i&gt;} override (optional) If true, the obj passed in becomes
* the execution scope of the listener
*/</span>
addListener : <span class="reserved">function</span>(eventName, fn, scope, override){
<span class="reserved">this</span>.events[eventName.toLowerCase()].subscribe(fn, scope, override);
},
<span class="comment">/**
* Shorthand for addListener
*/</span>
on : <span class="reserved">function</span>(eventName, fn, scope, override){
<span class="reserved">this</span>.events[eventName.toLowerCase()].subscribe(fn, scope, override);
},
removeListener : <span class="reserved">function</span>(eventName, fn, scope){
<span class="reserved">this</span>.events[eventName.toLowerCase()].unsubscribe(fn, scope);
},
<span class="comment">/** <span class="attrib">@ignore</span> */</span>
onClick : <span class="reserved">function</span>(e){
<span class="reserved">this</span>.fireEvent(<span class="literal">'click'</span>, e);
var target = e.getTarget();
var row = <span class="reserved">this</span>.getRowFromChild(target);
var cell = <span class="reserved">this</span>.getCellFromChild(target);
var header = <span class="reserved">this</span>.getHeaderFromChild(target);
<span class="reserved">if</span>(row){
<span class="reserved">this</span>.fireEvent(<span class="literal">'rowclick'</span>, <span class="reserved">this</span>, row.rowIndex, e);
}
<span class="reserved">if</span>(cell){
<span class="reserved">this</span>.fireEvent(<span class="literal">'cellclick'</span>, <span class="reserved">this</span>, row.rowIndex, cell.columnIndex, e);
}
<span class="reserved">if</span>(header){
<span class="reserved">this</span>.fireEvent(<span class="literal">'headerclick'</span>, <span class="reserved">this</span>, header.columnIndex, e);
}
},
<span class="comment">/** <span class="attrib">@ignore</span> */</span>
onContextMenu : <span class="reserved">function</span>(e){
var target = e.getTarget();
var row = <span class="reserved">this</span>.getRowFromChild(target);
var header = <span class="reserved">this</span>.getHeaderFromChild(target);
<span class="reserved">if</span>(row){
<span class="reserved">this</span>.fireEvent(<span class="literal">'rowcontextmenu'</span>, <span class="reserved">this</span>, row.rowIndex, e);
}
<span class="reserved">if</span>(header){
<span class="reserved">this</span>.fireEvent(<span class="literal">'headercontextmenu'</span>, <span class="reserved">this</span>, header.columnIndex, e);
}
e.preventDefault();
},
<span class="comment">/** <span class="attrib">@ignore</span> */</span>
onDblClick : <span class="reserved">function</span>(e){
<span class="reserved">this</span>.fireEvent(<span class="literal">'dblclick'</span>, e);
var target = e.getTarget();
var row = <span class="reserved">this</span>.getRowFromChild(target);
var cell = <span class="reserved">this</span>.getCellFromChild(target);
<span class="reserved">if</span>(row){
<span class="reserved">this</span>.fireEvent(<span class="literal">'rowdblclick'</span>, <span class="reserved">this</span>, row.rowIndex, e);
}
<span class="reserved">if</span>(cell){
<span class="reserved">this</span>.fireEvent(<span class="literal">'celldblclick'</span>, <span class="reserved">this</span>, row.rowIndex, cell.columnIndex, e);
}
},
<span class="comment">/**
* Starts editing the specified for the specified row/column
*/</span>
startEditing : <span class="reserved">function</span>(rowIndex, colIndex){
var row = <span class="reserved">this</span>.rows[rowIndex];
var cell = row.childNodes[colIndex];
<span class="reserved">this</span>.stopEditing();
setTimeout(<span class="reserved">this</span>.doEdit.createDelegate(<span class="reserved">this</span>, [row, cell]), 10);
},
<span class="comment">/**
* Stops any active editing
*/</span>
stopEditing : <span class="reserved">function</span>(){
<span class="reserved">if</span>(<span class="reserved">this</span>.activeEditor){
<span class="reserved">this</span>.activeEditor.stopEditing();
}
},
<span class="comment">/** <span class="attrib">@ignore</span> */</span>
doEdit : <span class="reserved">function</span>(row, cell){
<span class="reserved">if</span>(!row || !cell) <span class="reserved">return</span>;
var cm = <span class="reserved">this</span>.colModel;
var dm = <span class="reserved">this</span>.dataModel;
var colIndex = cell.columnIndex;
var rowIndex = row.rowIndex;
<span class="reserved">if</span>(cm.isCellEditable(colIndex, rowIndex)){
var ed = cm.getCellEditor(colIndex, rowIndex);
<span class="reserved">if</span>(ed){
<span class="reserved">if</span>(<span class="reserved">this</span>.activeEditor){
<span class="reserved">this</span>.activeEditor.stopEditing();
}
<span class="reserved">this</span>.fireEvent(<span class="literal">'beforeedit'</span>, <span class="reserved">this</span>, rowIndex, colIndex);
<span class="reserved">this</span>.activeEditor = ed;
<span class="reserved">this</span>.editingCell = cell;
<span class="reserved">this</span>.view.ensureVisible(row, true);
try{
cell.focus();
}catch(e){}
ed.init(<span class="reserved">this</span>, <span class="reserved">this</span>.el.dom.parentNode, <span class="reserved">this</span>.setValueDelegate);
var value = dm.getValueAt(rowIndex, cm.getDataIndex(colIndex));
<span class="comment">// set timeout so firefox stops editing before starting a new edit</span>
setTimeout(ed.startEditing.createDelegate(ed, [value, row, cell]), 1);
}
}
},
setCellValue : <span class="reserved">function</span>(value, rowIndex, colIndex){
<span class="reserved">this</span>.dataModel.setValueAt(value, rowIndex, <span class="reserved">this</span>.colModel.getDataIndex(colIndex));
<span class="reserved">this</span>.fireEvent(<span class="literal">'afteredit'</span>, <span class="reserved">this</span>, rowIndex, colIndex);
},
<span class="comment">/** <span class="attrib">@ignore</span> Called when text selection starts or mousedown to prevent default */</span>
cancelTextSelection : <span class="reserved">function</span>(e){
var target = e.getTarget();
<span class="reserved">if</span>(target &amp;&amp; target != <span class="reserved">this</span>.el.dom.parentNode &amp;&amp; !<span class="reserved">this</span>.allowTextSelectionPattern.test(target.tagName)){
e.preventDefault();
}
},
<span class="comment">/**
* Causes the grid to manually recalculate it's dimensions. Generally this is done automatically,
* but if manual update is required this method will initiate it.
*/</span>
autoSize : <span class="reserved">function</span>(){
<span class="reserved">this</span>.view.updateWrapHeight();
<span class="reserved">this</span>.view.adjustForScroll();
},
<span class="comment">/**
* Scrolls the grid to the specified row
* <span class="attrib">@param</span> {Number/HTMLElement} row The row object or index of the row
*/</span>
scrollTo : <span class="reserved">function</span>(row){
<span class="reserved">if</span>(typeof row == <span class="literal">'number'</span>){
row = <span class="reserved">this</span>.rows[row];
}
<span class="reserved">this</span>.view.ensureVisible(row, true);
},
<span class="comment">/** <span class="attrib">@private</span> */</span>
getEditingCell : <span class="reserved">function</span>(){
<span class="reserved">return</span> <span class="reserved">this</span>.editingCell;
},
<span class="comment">/**
* Binds this grid to the field with the specified id. Initially reads and parses the comma
* delimited ids in the field and selects those items. All selections made in the grid
* will be persisted to the field by their ids comma delimited.
* <span class="attrib">@param</span> {String} The id of the field to bind to
*/</span>
bindToField : <span class="reserved">function</span>(fieldId){
<span class="reserved">this</span>.fieldId = fieldId;
<span class="reserved">this</span>.readField();
},
<span class="comment">/** <span class="attrib">@private</span> */</span>
updateField : <span class="reserved">function</span>(){
<span class="reserved">if</span>(<span class="reserved">this</span>.fieldId){
var field = YAHOO.util.Dom.get(<span class="reserved">this</span>.fieldId);
field.value = <span class="reserved">this</span>.getSelectedRowIds().join(<span class="literal">','</span>);
}
},
<span class="comment">/**
* Causes the grid to read and select the ids from the bound field - See {<span class="attrib">@link</span> #bindToField}.
*/</span>
readField : <span class="reserved">function</span>(){
<span class="reserved">if</span>(<span class="reserved">this</span>.fieldId){
var field = YAHOO.util.Dom.get(<span class="reserved">this</span>.fieldId);
var values = field.value.split(<span class="literal">','</span>);
var rows = <span class="reserved">this</span>.getRowsById(values);
<span class="reserved">this</span>.selModel.selectRows(rows, false);
}
},
<span class="comment">/**
* Returns the table row at the specified index
* <span class="attrib">@return</span> {HTMLElement}
*/</span>
getRow : <span class="reserved">function</span>(index){
<span class="reserved">return</span> <span class="reserved">this</span>.rows[index];
},
<span class="comment">/**
* Returns the rows that have the specified id(s). The id value for a row is provided
* by the DataModel. See {<span class="attrib">@link</span> YAHOO.ext.grid.DefaultDataModel#getRowId}.
* <span class="attrib">@param</span> {String/Array} An id to find or an array of ids
* <span class="attrib">@return</span> {HtmlElement/Array} If one id was passed in, it returns one result.
* If an array of ids was specified, it returns an Array of HTMLElements
*/</span>
getRowsById : <span class="reserved">function</span>(id){
var dm = <span class="reserved">this</span>.dataModel;
<span class="reserved">if</span>(!(id instanceof Array)){
<span class="reserved">for</span>(var i = 0; i &lt; <span class="reserved">this</span>.rows.length; i++){
<span class="reserved">if</span>(dm.getRowId(i) == id){
<span class="reserved">return</span> <span class="reserved">this</span>.rows[i];
}
}
<span class="reserved">return</span> null;
}
var found = [];
var re = <span class="literal">"^(?:"</span>;
<span class="reserved">for</span>(var i = 0; i &lt; id.length; i++){
re += id[i];
<span class="reserved">if</span>(i != id.length-1) re += <span class="literal">"|"</span>;
}
var regex = new RegExp(re + <span class="literal">")$"</span>);
<span class="reserved">for</span>(var i = 0; i &lt; <span class="reserved">this</span>.rows.length; i++){
<span class="reserved">if</span>(regex.test(dm.getRowId(i))){
found.push(<span class="reserved">this</span>.rows[i]);
}
}
<span class="reserved">return</span> found;
},
<span class="comment">/**
* Returns the row that comes after the specified row - text nodes are skipped.
* <span class="attrib">@param</span> {HTMLElement} row
* <span class="attrib">@return</span> {HTMLElement}
*/</span>
getRowAfter : <span class="reserved">function</span>(row){
<span class="reserved">return</span> <span class="reserved">this</span>.getSibling(<span class="literal">'next'</span>, row);
},
<span class="comment">/**
* Returns the row that comes before the specified row - text nodes are skipped.
* <span class="attrib">@param</span> {HTMLElement} row
* <span class="attrib">@return</span> {HTMLElement}
*/</span>
getRowBefore : <span class="reserved">function</span>(row){
<span class="reserved">return</span> <span class="reserved">this</span>.getSibling(<span class="literal">'previous'</span>, row);
},
<span class="comment">/**
* Returns the cell that comes after the specified cell - text nodes are skipped.
* <span class="attrib">@param</span> {HTMLElement} cell
* <span class="attrib">@param</span> {Boolean} includeHidden
* <span class="attrib">@return</span> {HTMLElement}
*/</span>
getCellAfter : <span class="reserved">function</span>(cell, includeHidden){
var next = <span class="reserved">this</span>.getSibling(<span class="literal">'next'</span>, cell);
<span class="reserved">if</span>(next &amp;&amp; !includeHidden &amp;&amp; <span class="reserved">this</span>.colModel.isHidden(next.columnIndex)){
<span class="reserved">return</span> <span class="reserved">this</span>.getCellAfter(next);
}
<span class="reserved">return</span> next;
},
<span class="comment">/**
* Returns the cell that comes before the specified cell - text nodes are skipped.
* <span class="attrib">@param</span> {HTMLElement} cell
* <span class="attrib">@param</span> {Boolean} includeHidden
* <span class="attrib">@return</span> {HTMLElement}
*/</span>
getCellBefore : <span class="reserved">function</span>(cell, includeHidden){
var prev = <span class="reserved">this</span>.getSibling(<span class="literal">'previous'</span>, cell);
<span class="reserved">if</span>(prev &amp;&amp; !includeHidden &amp;&amp; <span class="reserved">this</span>.colModel.isHidden(prev.columnIndex)){
<span class="reserved">return</span> <span class="reserved">this</span>.getCellBefore(prev);
}
<span class="reserved">return</span> prev;
},
<span class="comment">/**
* Returns the last cell for the row - text nodes and hidden columns are skipped.
* <span class="attrib">@param</span> {HTMLElement} row
* <span class="attrib">@param</span> {Boolean} includeHidden
* <span class="attrib">@return</span> {HTMLElement}
*/</span>
getLastCell : <span class="reserved">function</span>(row, includeHidden){
var cell = <span class="reserved">this</span>.getElement(<span class="literal">'previous'</span>, row.lastChild);
<span class="reserved">if</span>(cell &amp;&amp; !includeHidden &amp;&amp; <span class="reserved">this</span>.colModel.isHidden(cell.columnIndex)){
<span class="reserved">return</span> <span class="reserved">this</span>.getCellBefore(cell);
}
<span class="reserved">return</span> cell;
},
<span class="comment">/**
* Returns the first cell for the row - text nodes and hidden columns are skipped.
* <span class="attrib">@param</span> {HTMLElement} row
* <span class="attrib">@param</span> {Boolean} includeHidden
* <span class="attrib">@return</span> {HTMLElement}
*/</span>
getFirstCell : <span class="reserved">function</span>(row, includeHidden){
var cell = <span class="reserved">this</span>.getElement(<span class="literal">'next'</span>, row.firstChild);
<span class="reserved">if</span>(cell &amp;&amp; !includeHidden &amp;&amp; <span class="reserved">this</span>.colModel.isHidden(cell.columnIndex)){
<span class="reserved">return</span> <span class="reserved">this</span>.getCellAfter(cell);
}
<span class="reserved">return</span> cell;
},
<span class="comment">/**
* Gets siblings, skipping text nodes
* <span class="attrib">@param</span> {String} type The direction to walk: 'next' or 'previous'
* <span class="attrib">@private</span>
*/</span>
getSibling : <span class="reserved">function</span>(type, node){
<span class="reserved">if</span>(!node) <span class="reserved">return</span> null;
type += <span class="literal">'Sibling'</span>;
var n = node[type];
<span class="reserved">while</span>(n &amp;&amp; n.nodeType != 1){
n = n[type];
}
<span class="reserved">return</span> n;
},
<span class="comment">/**
* Returns node if node is an HTMLElement else walks the siblings in direction looking for
* a node that is an element
* <span class="attrib">@param</span> {String} direction The direction to walk: 'next' or 'previous'
* <span class="attrib">@private</span>
*/</span>
getElement : <span class="reserved">function</span>(direction, node){
<span class="reserved">if</span>(!node || node.nodeType == 1) <span class="reserved">return</span> node;
<span class="reserved">else</span> <span class="reserved">return</span> <span class="reserved">this</span>.getSibling(direction, node);
},
<span class="comment">/**
* <span class="attrib">@private</span>
*/</span>
getElementFromChild : <span class="reserved">function</span>(childEl, parentClass){
<span class="reserved">if</span>(!childEl || (YAHOO.util.Dom.hasClass(childEl, parentClass))){
<span class="reserved">return</span> childEl;
}
var p = childEl.parentNode;
<span class="reserved">while</span>(p &amp;&amp; p.tagName.toUpperCase() != <span class="literal">'BODY'</span>){
<span class="reserved">if</span>(YAHOO.util.Dom.hasClass(p, parentClass)){
<span class="reserved">return</span> p;
}
p = p.parentNode;
}
<span class="reserved">return</span> null;
},
<span class="comment">/**
* Returns the row that contains the specified child element.
* <span class="attrib">@param</span> {HTMLElement} childEl
* <span class="attrib">@return</span> {HTMLElement}
*/</span>
getRowFromChild : <span class="reserved">function</span>(childEl){
<span class="reserved">return</span> <span class="reserved">this</span>.getElementFromChild(childEl, <span class="literal">'ygrid-row'</span>);
},
<span class="comment">/**
* Returns the cell that contains the specified child element.
* <span class="attrib">@param</span> {HTMLElement} childEl
* <span class="attrib">@return</span> {HTMLElement}
*/</span>
getCellFromChild : <span class="reserved">function</span>(childEl){
<span class="reserved">return</span> <span class="reserved">this</span>.getElementFromChild(childEl, <span class="literal">'ygrid-col'</span>);
},
<span class="comment">/**
* Returns the header element that contains the specified child element.
* <span class="attrib">@param</span> {HTMLElement} childEl
* <span class="attrib">@return</span> {HTMLElement}
*/</span>
getHeaderFromChild : <span class="reserved">function</span>(childEl){
<span class="reserved">return</span> <span class="reserved">this</span>.getElementFromChild(childEl, <span class="literal">'ygrid-hd'</span>);
},
<span class="comment">/**
* Convenience method for getSelectionModel().getSelectedRows() -
* See &lt;small&gt;{<span class="attrib">@link</span> YAHOO.ext.grid.DefaultSelectionModel#getSelectedRows}&lt;/small&gt; for more details.
*/</span>
getSelectedRows : <span class="reserved">function</span>(){
<span class="reserved">return</span> <span class="reserved">this</span>.selModel.getSelectedRows();
},
<span class="comment">/**
* Convenience method for getSelectionModel().getSelectedRows()[0] -
* See &lt;small&gt;{<span class="attrib">@link</span> YAHOO.ext.grid.DefaultSelectionModel#getSelectedRows}&lt;/small&gt; for more details.
*/</span>
getSelectedRow : <span class="reserved">function</span>(){
<span class="reserved">if</span>(<span class="reserved">this</span>.selModel.hasSelection()){
<span class="reserved">return</span> <span class="reserved">this</span>.selModel.getSelectedRows()[0];
}
<span class="reserved">return</span> null;
},
<span class="comment">/**
* Get the selected row indexes
* <span class="attrib">@return</span> {Array} Array of indexes
*/</span>
getSelectedRowIndexes : <span class="reserved">function</span>(){
var a = [];
var rows = <span class="reserved">this</span>.selModel.getSelectedRows();
<span class="reserved">for</span>(var i = 0; i &lt; rows.length; i++) {
a[i] = rows[i].rowIndex;
}
<span class="reserved">return</span> a;
},
<span class="comment">/**
* Gets the first selected row or -1 if none are selected
* <span class="attrib">@return</span> {Number}
*/</span>
getSelectedRowIndex : <span class="reserved">function</span>(){
<span class="reserved">if</span>(<span class="reserved">this</span>.selModel.hasSelection()){
<span class="reserved">return</span> <span class="reserved">this</span>.selModel.getSelectedRows()[0].rowIndex;
}
<span class="reserved">return</span> -1;
},
<span class="comment">/**
* Convenience method for getSelectionModel().getSelectedRowIds()[0] -
* See &lt;small&gt;{<span class="attrib">@link</span> YAHOO.ext.grid.DefaultSelectionModel#getSelectedRowIds}&lt;/small&gt; for more details.
*/</span>
getSelectedRowId : <span class="reserved">function</span>(){
<span class="reserved">if</span>(<span class="reserved">this</span>.selModel.hasSelection()){
<span class="reserved">return</span> <span class="reserved">this</span>.selModel.getSelectedRowIds()[0];
}
<span class="reserved">return</span> null;
},
<span class="comment">/**
* Convenience method for getSelectionModel().getSelectedRowIds() -
* See &lt;small&gt;{<span class="attrib">@link</span> YAHOO.ext.grid.DefaultSelectionModel#getSelectedRowIds}&lt;/small&gt; for more details.
*/</span>
getSelectedRowIds : <span class="reserved">function</span>(){
<span class="reserved">return</span> <span class="reserved">this</span>.selModel.getSelectedRowIds();
},
<span class="comment">/**
* Convenience method for getSelectionModel().clearSelections() -
* See &lt;small&gt;{<span class="attrib">@link</span> YAHOO.ext.grid.DefaultSelectionModel#clearSelections}&lt;/small&gt; for more details.
*/</span>
clearSelections : <span class="reserved">function</span>(){
<span class="reserved">this</span>.selModel.clearSelections();
},
<span class="comment">/**
* Convenience method for getSelectionModel().selectAll() -
* See &lt;small&gt;{<span class="attrib">@link</span> YAHOO.ext.grid.DefaultSelectionModel#selectAll}&lt;/small&gt; for more details.
*/</span>
selectAll : <span class="reserved">function</span>(){
<span class="reserved">this</span>.selModel.selectAll();
},
<span class="comment">/**
* Convenience method for getSelectionModel().getCount() -
* See &lt;small&gt;{<span class="attrib">@link</span> YAHOO.ext.grid.DefaultSelectionModel#getCount}&lt;/small&gt; for more details.
*/</span>
getSelectionCount : <span class="reserved">function</span>(){
<span class="reserved">return</span> <span class="reserved">this</span>.selModel.getCount();
},
<span class="comment">/**
* Convenience method for getSelectionModel().hasSelection() -
* See &lt;small&gt;{<span class="attrib">@link</span> YAHOO.ext.grid.DefaultSelectionModel#hasSelection}&lt;/small&gt; for more details.
*/</span>
hasSelection : <span class="reserved">function</span>(){
<span class="reserved">return</span> <span class="reserved">this</span>.selModel.hasSelection();
},
<span class="comment">/**
* Returns the grid's SelectionModel.
*/</span>
getSelectionModel : <span class="reserved">function</span>(){
<span class="reserved">if</span>(!<span class="reserved">this</span>.selModel){
<span class="reserved">this</span>.selModel = new DefaultSelectionModel();
}
<span class="reserved">return</span> <span class="reserved">this</span>.selModel;
},
<span class="comment">/**
* Returns the grid's DataModel.
*/</span>
getDataModel : <span class="reserved">function</span>(){
<span class="reserved">return</span> <span class="reserved">this</span>.dataModel;
},
<span class="comment">/**
* Returns the grid's ColumnModel.
*/</span>
getColumnModel : <span class="reserved">function</span>(){
<span class="reserved">return</span> <span class="reserved">this</span>.colModel;
},
<span class="comment">/**
* Returns the grid's GridView object.
*/</span>
getView : <span class="reserved">function</span>(){
<span class="reserved">return</span> <span class="reserved">this</span>.view;
},
<span class="comment">/**
* Called to get grid's drag proxy text, by default returns this.ddText.
* <span class="attrib">@return</span> {String}
*/</span>
getDragDropText : <span class="reserved">function</span>(){
<span class="reserved">return</span> <span class="reserved">this</span>.ddText.replace(<span class="literal">'%0'</span>, <span class="reserved">this</span>.selModel.getCount());
}
};
<span class="comment">/**
* Configures the text is the drag proxy (defaults to "%0 selected row(s)").
* %0 is replaced with the number of selected rows.
* <span class="attrib">@type</span> String
*/</span>
YAHOO.ext.grid.Grid.<span class="reserved">prototype</span>.ddText = <span class="literal">"%0 selected row(s)"</span>;</pre>
<hr>
<hr>
<font size="-1">
</font>
<div class="jsdoc_ctime">Documentation generated by <a href="http://jsdoc.sourceforge.net/" target="_parent">JSDoc</a> on Sat Oct 14 06:07:10 2006</div>
</body>
</html>