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

📄 datatable.js

📁 这是YUI的源码及相关示例。里面有很多很炫的Javascript效果。
💻 JS
📖 第 1 页 / 共 5 页
字号:
        // Parse out Column instances from the array of object literals        if(YAHOO.lang.isArray(aDefinitions)) {            parseColumns(aDefinitions);            // Store the array            this._aDefinitions = aDefinitions;        }        else {            return null;        }        var i;        // Determine ROWSPAN value for each Column in the tree        var parseTreeForRowspan = function(tree) {            var maxRowDepth = 1;            var currentRow;            var currentColumn;            // Calculate the max depth of descendants for this row            var countMaxRowDepth = function(row, tmpRowDepth) {                tmpRowDepth = tmpRowDepth || 1;                for(var n=0; n<row.length; n++) {                    var col = row[n];                    // Column has children, so keep counting                    if(YAHOO.lang.isArray(col.children)) {                        tmpRowDepth++;                        countMaxRowDepth(col.children, tmpRowDepth);                        tmpRowDepth--;                    }                    // No children, is it the max depth?                    else {                        if(tmpRowDepth > maxRowDepth) {                            maxRowDepth = tmpRowDepth;                        }                    }                }            };            // Count max row depth for each row            for(var m=0; m<tree.length; m++) {                currentRow = tree[m];                countMaxRowDepth(currentRow);                // Assign the right ROWSPAN values to each Column in the row                for(var p=0; p<currentRow.length; p++) {                    currentColumn = currentRow[p];                    if(!YAHOO.lang.isArray(currentColumn.children)) {                        currentColumn._nRowspan = maxRowDepth;                    }                    else {                        currentColumn._nRowspan = 1;                    }                }                // Reset counter for next row                maxRowDepth = 1;            }        };        parseTreeForRowspan(tree);        // Store tree index values        for(i=0; i<tree[0].length; i++) {            tree[0][i]._nTreeIndex = i;        }        // Store header relationships in an array for HEADERS attribute        var recurseAncestorsForHeaders = function(i, oColumn) {            headers[i].push(oColumn.getSanitizedKey());            if(oColumn._oParent) {                recurseAncestorsForHeaders(i, oColumn._oParent);            }        };        for(i=0; i<keys.length; i++) {            headers[i] = [];            recurseAncestorsForHeaders(i, keys[i]);            headers[i] = headers[i].reverse();        }        // Save to the ColumnSet instance        this.tree = tree;        this.flat = flat;        this.keys = keys;        this.headers = headers;    },    /////////////////////////////////////////////////////////////////////////////    //    // Public methods    //    /////////////////////////////////////////////////////////////////////////////    /**     * Returns unique name of the ColumnSet instance.     *     * @method getId     * @return {String} Unique name of the ColumnSet instance.     */    getId : function() {        return this._sId;    },    /**     * ColumnSet instance name, for logging.     *     * @method toString     * @return {String} Unique name of the ColumnSet instance.     */    toString : function() {        return "ColumnSet instance " + this._sId;    },    /**     * Public accessor to the definitions array.     *     * @method getDefinitions     * @return {Object[]} Array of object literal Column definitions.     */    getDefinitions : function() {        var aDefinitions = this._aDefinitions;                // Internal recursive function to define Column instances        var parseColumns = function(nodeList, oSelf) {            // Parse each node at this depth for attributes and any children            for(var j=0; j<nodeList.length; j++) {                var currentNode = nodeList[j];                                // Get the Column for each node                var oColumn = oSelf.getColumnById(currentNode.yuiColumnId);                                if(oColumn) {                        // Update the current values                    var oDefinition = oColumn.getDefinition();                    for(var name in oDefinition) {                        if(YAHOO.lang.hasOwnProperty(oDefinition, name)) {                            currentNode[name] = oDefinition[name];                        }                    }                }                                            // The Column has descendants                if(YAHOO.lang.isArray(currentNode.children)) {                    // The children themselves must also be parsed for Column instances                    parseColumns(currentNode.children, oSelf);                }            }        };        parseColumns(aDefinitions, this);        this._aDefinitions = aDefinitions;        return aDefinitions;    },    /**     * Returns Column instance with given ID.     *     * @method getColumnById     * @param column {String} Column ID.     * @return {YAHOO.widget.Column} Column instance.     */    getColumnById : function(column) {        if(YAHOO.lang.isString(column)) {            var allColumns = this.flat;            for(var i=allColumns.length-1; i>-1; i--) {                if(allColumns[i]._sId === column) {                    return allColumns[i];                }            }        }        return null;    },    /**     * Returns Column instance with given key or ColumnSet key index.     *     * @method getColumn     * @param column {String | Number} Column key or ColumnSet key index.     * @return {YAHOO.widget.Column} Column instance.     */    getColumn : function(column) {        if(YAHOO.lang.isNumber(column) && this.keys[column]) {            return this.keys[column];        }        else if(YAHOO.lang.isString(column)) {            var allColumns = this.flat;            var aColumns = [];            for(var i=0; i<allColumns.length; i++) {                if(allColumns[i].key === column) {                    aColumns.push(allColumns[i]);                }            }            if(aColumns.length === 1) {                return aColumns[0];            }            else if(aColumns.length > 1) {                return aColumns;            }        }        return null;    },    /**     * Public accessor returns array of given Column's desendants (if any), including itself.     *     * @method getDescendants     * @parem {YAHOO.widget.Column} Column instance.     * @return {Array} Array including the Column itself and all descendants (if any).     */    getDescendants : function(oColumn) {        var oSelf = this;        var allDescendants = [];        var i;        // Recursive function to loop thru all children        var parse = function(oParent) {            allDescendants.push(oParent);            // This Column has children            if(oParent.children) {                for(i=0; i<oParent.children.length; i++) {                    parse(oSelf.getColumn(oParent.children[i].key));                }            }        };        parse(oColumn);        return allDescendants;    }};/****************************************************************************//****************************************************************************//****************************************************************************//** * The Column class defines and manages attributes of DataTable Columns * * @namespace YAHOO.widget * @class Column * @constructor * @param oConfigs {Object} Object literal of definitions. */YAHOO.widget.Column = function(oConfigs) {    this._sId = "yui-col" + YAHOO.widget.Column._nCount;        // Object literal defines Column attributes    if(oConfigs && YAHOO.lang.isObject(oConfigs)) {        for(var sConfig in oConfigs) {            if(sConfig) {                this[sConfig] = oConfigs[sConfig];            }        }    }    // Assign a key if not found    if(!YAHOO.lang.isValue(this.key)) {        this.key = "yui-dt-col" + YAHOO.widget.Column._nCount;    }        // Assign a field if not found, defaults to key    if(!YAHOO.lang.isValue(this.field)) {        this.field = this.key;    }    // Increment counter    YAHOO.widget.Column._nCount++;    // Backward compatibility    if(this.width && !YAHOO.lang.isNumber(this.width)) {        this.width = null;    }    if(this.editor && YAHOO.lang.isString(this.editor)) {        this.editor = new YAHOO.widget.CellEditor(this.editor, this.editorOptions);    }};///////////////////////////////////////////////////////////////////////////////// Private member variables///////////////////////////////////////////////////////////////////////////////YAHOO.lang.augmentObject(YAHOO.widget.Column, {    /**     * Internal class variable to index multiple Column instances.     *     * @property Column._nCount     * @type Number     * @private     * @static     */    _nCount : 0,    formatCheckbox : function(elCell, oRecord, oColumn, oData) {        YAHOO.widget.DataTable.formatCheckbox(elCell, oRecord, oColumn, oData);    },    formatCurrency : function(elCell, oRecord, oColumn, oData) {        YAHOO.widget.DataTable.formatCurrency(elCell, oRecord, oColumn, oData);    },    formatDate : function(elCell, oRecord, oColumn, oData) {        YAHOO.widget.DataTable.formatDate(elCell, oRecord, oColumn, oData);    },    formatEmail : function(elCell, oRecord, oColumn, oData) {        YAHOO.widget.DataTable.formatEmail(elCell, oRecord, oColumn, oData);    },    formatLink : function(elCell, oRecord, oColumn, oData) {        YAHOO.widget.DataTable.formatLink(elCell, oRecord, oColumn, oData);    },    formatNumber : function(elCell, oRecord, oColumn, oData) {        YAHOO.widget.DataTable.formatNumber(elCell, oRecord, oColumn, oData);    },    formatSelect : function(elCell, oRecord, oColumn, oData) {        YAHOO.widget.DataTable.formatDropdown(elCell, oRecord, oColumn, oData);    }});YAHOO.widget.Column.prototype = {    /**     * Unique String identifier assigned at instantiation.     *     * @property _sId     * @type String     * @private     */    _sId : null,    /**     * Reference to Column's current position index within its ColumnSet's keys     * array, if applicable. This property only applies to non-nested and bottom-     * level child Columns.     *     * @property _nKeyIndex     * @type Number     * @private     */    _nKeyIndex : null,    /**     * Reference to Column's current position index within its ColumnSet's tree     * array, if applicable. This property only applies to non-nested and top-     * level parent Columns.     *     * @property _nTreeIndex     * @type Number     * @private     */    _nTreeIndex : null,    /**     * Number of table cells the Column spans.     *     * @property _nColspan     * @type Number     * @private     */    _nColspan : 1,    /**     * Number of table rows the Column spans.     *     * @property _nRowspan     * @type Number     * @private     */    _nRowspan : 1,    /**     * Column's parent Column instance, or null.     *     * @property _oParent     * @type YAHOO.widget.Column     * @private     */    _oParent : null,    /**     * The DOM reference to the associated TH element.     *     * @property _elTh     * @type HTMLElement     * @private     */    _elTh : null,    /**     * The DOM reference to the associated TH element's liner DIV element.     *     * @property _elThLiner     * @type HTMLElement     * @private     */    _elThLiner : null,    /**     * The DOM reference to the associated TH element's label SPAN element.     *     * @property _elThLabel     * @type HTMLElement     * @private     */    _elThLabel : null,    /**     * The DOM reference to the associated resizerelement (if any).     *     * @property _elResizer     * @type HTMLElement

⌨️ 快捷键说明

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