⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gridview.js

📁 Ext JS是一个创建丰富互联网应用程序的跨浏览器的JavaScrip库。它包含:高效率
💻 JS
📖 第 1 页 / 共 4 页
字号:
/*
 * Ext JS Library 3.0 Pre-alpha
 * Copyright(c) 2006-2008, Ext JS, LLC.
 * licensing@extjs.com
 * 
 * http://extjs.com/license
 */

/** * @class Ext.grid.GridView * @extends Ext.util.Observable * <p>This class encapsulates the user interface of an {@link Ext.grid.GridPanel}. * Methods of this class may be used to access user interface elements to enable * special display effects. Do not change the DOM structure of the user interface.</p> * <p>This class does not provide ways to manipulate the underlying data. The data * model of a Grid is held in an {@link Ext.data.Store}.</p> * @constructor * @param {Object} config */Ext.grid.GridView = function(config){    Ext.apply(this, config);    // These events are only used internally by the grid components    this.addEvents(      /**         * @event beforerowremoved         * Internal UI Event. Fired before a row is removed.         * @param {Ext.grid.GridView} view         * @param {Number} rowIndex The index of the row to be removed.         * @param {Ext.data.Record} record The Record to be removed       */      "beforerowremoved",      /**         * @event beforerowsinserted         * Internal UI Event. Fired before rows are inserted.         * @param {Ext.grid.GridView} view         * @param {Number} firstRow The index of the first row to be inserted.         * @param {Number} lastRow The index of the last row to be inserted.       */      "beforerowsinserted",      /**         * @event beforerefresh         * Internal UI Event. Fired before the view is refreshed.         * @param {Ext.grid.GridView} view       */      "beforerefresh",      /**         * @event rowremoved         * Internal UI Event. Fired after a row is removed.         * @param {Ext.grid.GridView} view         * @param {Number} rowIndex The index of the row that was removed.         * @param {Ext.data.Record} record The Record that was removed       */      "rowremoved",      /**         * @event rowsinserted         * Internal UI Event. Fired after rows are inserted.         * @param {Ext.grid.GridView} view         * @param {Number} firstRow The index of the first inserted.         * @param {Number} lastRow The index of the last row inserted.       */      "rowsinserted",      /**         * @event rowupdated         * Internal UI Event. Fired after a row has been updated.         * @param {Ext.grid.GridView} view         * @param {Number} firstRow The index of the row updated.         * @param {Ext.data.record} record The Record backing the row updated.       */      "rowupdated",      /**         * @event refresh         * Internal UI Event. Fired after the GridView's body has been refreshed.         * @param {Ext.grid.GridView} view       */      "refresh"  );    Ext.grid.GridView.superclass.constructor.call(this);};Ext.extend(Ext.grid.GridView, Ext.util.Observable, {    /**     * Override this function to apply custom CSS classes to rows during rendering.  You can also supply custom     * parameters to the row template for the current row to customize how it is rendered using the <b>rowParams</b>     * parameter.  This function should return the CSS class name (or empty string '' for none) that will be added     * to the row's wrapping div.  To apply multiple class names, simply return them space-delimited within the string     * (e.g., 'my-class another-class'). Example usage:    <pre><code>viewConfig: {    forceFit: true,    showPreview: true, // custom property    enableRowBody: true, // required to create a second, full-width row to show expanded Record data    getRowClass: function(record, rowIndex, rp, ds){ // rp = rowParams        if(this.showPreview){            rp.body = '&lt;p>'+record.data.excerpt+'&lt;/p>';            return 'x-grid3-row-expanded';        }        return 'x-grid3-row-collapsed';    }},         </code></pre>     * @param {Record} record The {@link Ext.data.Record} corresponding to the current row.     * @param {Number} index The row index.     * @param {Object} rowParams A config object that is passed to the row template during rendering that allows     * customization of various aspects of a grid row.     * <p>If {@link #enableRowBody} is configured <b><tt></tt>true</b>, then the following properties may be set     * by this function, and will be used to render a full-width expansion row below each grid row:</p>     * <ul>     * <li><code>body</code> : String <div class="sub-desc">An HTML fragment to be used as the expansion row's body content (defaults to '').</div></li>     * <li><code>bodyStyle</code> : String <div class="sub-desc">A CSS style specification that will be applied to the expansion row's &lt;tr> element. (defaults to '').</div></li>     * </ul>     * The following property will be passed in, and may be appended to:     * <ul>     * <li><code>tstyle</code> : String <div class="sub-desc">A CSS style specification that willl be applied to the &lt;table> element which encapsulates     * both the standard grid row, and any expansion row.</div></li>     * </ul>     * @param {Store} store The {@link Ext.data.Store} this grid is bound to     * @method getRowClass     * @return {String} a CSS class name to add to the row.     */    /**     * @cfg {Boolean} enableRowBody True to add a second TR element per row that can be used to provide a row body     * that spans beneath the data row.  Use the {@link #getRowClass} method's rowParams config to customize the row body.     */    /**     * @cfg {String} emptyText Default text (html tags are accepted) to display in the grid body when no rows     * are available (defaults to ''). This value will be used to update the <tt>{@link #mainBody}</tt>:    <pre><code>    this.mainBody.update('&lt;div class="x-grid-empty">' + this.emptyText + '&lt;/div>');    </code></pre>     */    /**     * @cfg {Boolean} headersDisabled True to disable the grid column headers (defaults to <tt>false</tt>).      * Use the {@link Ext.grid.ColumnModel ColumnModel} <tt>{@link Ext.grid.ColumnModel#menuDisabled menuDisabled}</tt>     * config to disable the <i>menu</i> for individual columns.  While this config is true the     * following will be disabled:<div class="mdetail-params"><ul>     * <li>clicking on header to sort</li>     * <li>the trigger to reveal the menu.</li>     * </ul></div>     */    /**     * <p>A customized implementation of a {@link Ext.dd.DragZone DragZone} which provides default implementations     * of the template methods of DragZone to enable dragging of the selected rows of a GridPanel.     * See {@link Ext.grid.GridDragZone} for details.</p>     * <p>This will <b>only</b> be present:<div class="mdetail-params"><ul>     * <li><i>if</i> the owning GridPanel was configured with {@link Ext.grid.GridPanel#enableDragDrop enableDragDrop}: <tt>true</tt>.</li>     * <li><i>after</i> the owning GridPanel has been rendered.</li>     * </ul></div>     * @property dragZone     * @type {Ext.grid.GridDragZone}     */    /**     * @cfg {Boolean} deferEmptyText True to defer <tt>{@link #emptyText}</tt> being applied until the store's     * first load (defaults to <tt>true</tt>).     */    deferEmptyText : true,    /**     * @cfg {Number} scrollOffset The amount of space to reserve for the vertical scrollbar     * (defaults to <tt>19</tt> pixels).     */    scrollOffset : 19,    /**     * @cfg {Boolean} autoFill     * Defaults to <tt>false</tt>.  Specify <tt>true</tt> to have the column widths re-proportioned     * when the grid is <b>initially rendered</b>.  The      * {@link Ext.grid.Column#width initially configured width}</tt> of each column will be adjusted     * to fit the grid width and prevent horizontal scrolling. If columns are later resized (manually     * or programmatically), the other columns in the grid will <b>not</b> be resized to fit the grid width.     * See <tt>{@link #forceFit}</tt> also.     */    autoFill : false,    /**     * @cfg {Boolean} forceFit     * Defaults to <tt>false</tt>.  Specify <tt>true</tt> to have the column widths re-proportioned     * at <b>all times</b>.  The {@link Ext.grid.Column#width initially configured width}</tt> of each     * column will be adjusted to fit the grid width and prevent horizontal scrolling. If columns are     * later resized (manually or programmatically), the other columns in the grid <b>will</b> be resized     * to fit the grid width. See <tt>{@link #autoFill}</tt> also.     */    forceFit : false,    /**     * @cfg {Array} sortClasses The CSS classes applied to a header when it is sorted. (defaults to <tt>["sort-asc", "sort-desc"]</tt>)     */    sortClasses : ["sort-asc", "sort-desc"],    /**     * @cfg {String} sortAscText The text displayed in the "Sort Ascending" menu item (defaults to <tt>"Sort Ascending"</tt>)     */    sortAscText : "Sort Ascending",    /**     * @cfg {String} sortDescText The text displayed in the "Sort Descending" menu item (defaults to <tt>"Sort Descending"</tt>)     */    sortDescText : "Sort Descending",    /**     * @cfg {String} columnsText The text displayed in the "Columns" menu item (defaults to <tt>"Columns"</tt>)     */    columnsText : "Columns",    /**     * @cfg {String} selectedRowClass The CSS class applied to a selected row (defaults to <tt>"x-grid3-row-selected"</tt>). An     * example overriding the default styling:    <pre><code>    .x-grid3-row-selected {background-color: yellow;}    </code></pre>     * Note that this only controls the row, and will not do anything for the text inside it.  To style inner     * facets (like text) use something like:    <pre><code>    .x-grid3-row-selected .x-grid3-cell-inner {    	color: #FFCC00;    }    </code></pre>     * @type String     */    selectedRowClass : "x-grid3-row-selected",    // private    borderWidth : 2,    tdClass : 'x-grid3-cell',    hdCls : 'x-grid3-hd',    markDirty : true,    /**     * @cfg {Number} cellSelectorDepth The number of levels to search for cells in event delegation (defaults to <tt>4</tt>)     */    cellSelectorDepth : 4,    /**     * @cfg {Number} rowSelectorDepth The number of levels to search for rows in event delegation (defaults to <tt>10</tt>)     */    rowSelectorDepth : 10,    /**     * @cfg {String} cellSelector The selector used to find cells internally (defaults to <tt>'td.x-grid3-cell'</tt>)     */    cellSelector : 'td.x-grid3-cell',    /**     * @cfg {String} rowSelector The selector used to find rows internally (defaults to <tt>'div.x-grid3-row'</tt>)     */    rowSelector : 'div.x-grid3-row',    /* -------------------------------- UI Specific ----------------------------- */    // private    initTemplates : function(){        var ts = this.templates || {};        if(!ts.master){            ts.master = new Ext.Template(                    '<div class="x-grid3" hidefocus="true">',                        '<div class="x-grid3-viewport">',                            '<div class="x-grid3-header"><div class="x-grid3-header-inner"><div class="x-grid3-header-offset" style="{ostyle}">{header}</div></div><div class="x-clear"></div></div>',                            '<div class="x-grid3-scroller"><div class="x-grid3-body" style="{bstyle}">{body}</div><a href="#" class="x-grid3-focus" tabIndex="-1"></a></div>',                        '</div>',                        '<div class="x-grid3-resize-marker">&#160;</div>',                        '<div class="x-grid3-resize-proxy">&#160;</div>',                    '</div>'                    );        }        if(!ts.header){            ts.header = new Ext.Template(                    '<table border="0" cellspacing="0" cellpadding="0" style="{tstyle}">',                    '<thead><tr class="x-grid3-hd-row">{cells}</tr></thead>',                    '</table>'                    );        }        if(!ts.hcell){            ts.hcell = new Ext.Template(                    '<td class="x-grid3-hd x-grid3-cell x-grid3-td-{id} {css}" style="{style}"><div {tooltip} {attr} class="x-grid3-hd-inner x-grid3-hd-{id}" unselectable="on" style="{istyle}">', this.grid.enableHdMenu ? '<a class="x-grid3-hd-btn" href="#"></a>' : '',                    '{value}<img class="x-grid3-sort-icon" src="', Ext.BLANK_IMAGE_URL, '" />',                    '</div></td>'                    );        }        if(!ts.body){            ts.body = new Ext.Template('{rows}');        }        if(!ts.row){            ts.row = new Ext.Template(                    '<div class="x-grid3-row {alt}" style="{tstyle}"><table class="x-grid3-row-table" border="0" cellspacing="0" cellpadding="0" style="{tstyle}">',                    '<tbody><tr>{cells}</tr>',                    (this.enableRowBody ? '<tr class="x-grid3-row-body-tr" style="{bodyStyle}"><td colspan="{cols}" class="x-grid3-body-cell" tabIndex="0" hidefocus="on"><div class="x-grid3-row-body">{body}</div></td></tr>' : ''),                    '</tbody></table></div>'                    );        }        if(!ts.cell){            ts.cell = new Ext.Template(                    '<td class="x-grid3-col x-grid3-cell x-grid3-td-{id} {css}" style="{style}" tabIndex="0" {cellAttr}>',                    '<div class="x-grid3-cell-inner x-grid3-col-{id}" unselectable="on" {attr}>{value}</div>',                    '</td>'                    );        }        for(var k in ts){            var t = ts[k];            if(t && typeof t.compile == 'function' && !t.compiled){                t.disableFormats = true;                t.compile();            }        }        this.templates = ts;        this.colRe = new RegExp("x-grid3-td-([^\\s]+)", "");    },    // private    fly : function(el){        if(!this._flyweight){            this._flyweight = new Ext.Element.Flyweight(document.body);        }        this._flyweight.dom = el;        return this._flyweight;    },    // private    getEditorParent : function(ed){        return this.scroller.dom;    },    // private    initElements : function(){        var E = Ext.Element;        var el = this.grid.getGridEl().dom.firstChild;        var cs = el.childNodes;        this.el = new E(el);        this.mainWrap = new E(cs[0]);        this.mainHd = new E(this.mainWrap.dom.firstChild);        if(this.grid.hideHeaders){            this.mainHd.setDisplayed(false);        }        this.innerHd = this.mainHd.dom.firstChild;        this.scroller = new E(this.mainWrap.dom.childNodes[1]);        if(this.forceFit){            this.scroller.setStyle('overflow-x', 'hidden');        }        /**         * <i>Read-only</i>. The GridView's body Element which encapsulates all rows in the Grid.         * This {@link Ext.Element Element} is only available after the GridPanel has been rendered.         * @type Ext.Element         * @property mainBody         */        this.mainBody = new E(this.scroller.dom.firstChild);        this.focusEl = new E(this.scroller.dom.childNodes[1]);        this.focusEl.swallowEvent("click", true);        this.resizeMarker = new E(cs[1]);        this.resizeProxy = new E(cs[2]);    },    // private    getRows : function(){        return this.hasRows() ? this.mainBody.dom.childNodes : [];    },    // finder methods, used with delegation    // private    findCell : function(el){        if(!el){            return false;        }        return this.fly(el).findParent(this.cellSelector, this.cellSelectorDepth);    },    // private    findCellIndex : function(el, requiredCls){        var cell = this.findCell(el);        if(cell && (!requiredCls || this.fly(cell).hasClass(requiredCls))){            return this.getCellIndex(cell);        }        return false;    },    // private    getCellIndex : function(el){        if(el){            var m = el.className.match(this.colRe);            if(m && m[1]){                return this.cm.getIndexById(m[1]);            }        }        return false;    },    // private    findHeaderCell : function(el){        var cell = this.findCell(el);        return cell && this.fly(cell).hasClass(this.hdCls) ? cell : null;    },    // private    findHeaderIndex : function(el){        return this.findCellIndex(el, this.hdCls);    },/** * Return the HtmlElement representing the grid row which contains the passed element. * @param {Element} el The target element * @return The row element, or null if the target element is not within a row of this GridView. */    findRow : function(el){        if(!el){            return false;        }        return this.fly(el).findParent(this.rowSelector, this.rowSelectorDepth);    },/** * Return the index of the grid row which contains the passed element. * @param {Element} el The target element * @return The row index, or <b>false</b> if the target element is not within a row of this GridView. */    findRowIndex : function(el){        var r = this.findRow(el);        return r ? r.rowIndex : false;    },    // getter methods for fetching elements dynamically in the grid/** * Return the &lt;TR> HtmlElement which represents a Grid row for the specified index. * @param {Number} index The row index * @return {HtmlElement} The &lt;TR> element. */    getRow : function(row){        return this.getRows()[row];    },/** * Returns the grid's &lt;TD> HtmlElement at the specified coordinates.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -