📄 datatable.js
字号:
* Unique String identifier assigned at instantiation. * * @property _sId * @type String * @private */ _sId : null, /** * Internal counter of how many Records are in the RecordSet. * * @property _length * @type Number * @private * @deprecated No longer used */ //_length : null, ///////////////////////////////////////////////////////////////////////////// // // Private methods // ///////////////////////////////////////////////////////////////////////////// /** * Adds one Record to the RecordSet at the given index. If index is null, * then adds the Record to the end of the RecordSet. * * @method _addRecord * @param oData {Object} An object literal of data. * @param index {Number} (optional) Position index. * @return {YAHOO.widget.Record} A Record instance. * @private */ _addRecord : function(oData, index) { var oRecord = new YAHOO.widget.Record(oData); if(YAHOO.lang.isNumber(index) && (index > -1)) { this._records.splice(index,0,oRecord); } else { //index = this.getLength(); //this._records[index] = oRecord; this._records[this._records.length] = oRecord; } //this._length++; return oRecord; }, /** * Sets/replaces one Record to the RecordSet at the given index. Existing * Records with higher indexes are not shifted. If no index specified, the * Record is added to the end of the RecordSet. * * @method _setRecord * @param oData {Object} An object literal of data. * @param index {Number} (optional) Position index. * @return {YAHOO.widget.Record} A Record instance. * @private */ _setRecord : function(oData, index) { if (!lang.isNumber(index) || index < 0) { index = this._records.length; } return (this._records[index] = new widget.Record(oData)); /* if(lang.isNumber(index) && (index > -1)) { this._records[index] = oRecord; if((index+1) > this.getLength()) { this._length = index+1; } } else { this._records[this.getLength()] = oRecord; this._length++; } return oRecord; */ }, /** * Deletes Records from the RecordSet at the given index. If range is null, * then only one Record is deleted. * * @method _deleteRecord * @param index {Number} Position index. * @param range {Number} (optional) How many Records to delete * @private */ _deleteRecord : function(index, range) { if(!lang.isNumber(range) || (range < 0)) { range = 1; } this._records.splice(index, range); //this._length = this._length - range; }, ///////////////////////////////////////////////////////////////////////////// // // Public methods // ///////////////////////////////////////////////////////////////////////////// /** * Returns unique name of the RecordSet instance. * * @method getId * @return {String} Unique name of the RecordSet instance. */ getId : function() { return this._sId; }, /** * Public accessor to the unique name of the RecordSet instance. * * @method toString * @return {String} Unique name of the RecordSet instance. */ toString : function() { return "RecordSet instance " + this._sId; }, /** * Returns the number of Records held in the RecordSet. * * @method getLength * @return {Number} Number of records in the RecordSet. */ getLength : function() { //return this._length; return this._records.length; }, /** * Returns Record by ID or RecordSet position index. * * @method getRecord * @param record {YAHOO.widget.Record | Number | String} Record instance, * RecordSet position index, or Record ID. * @return {YAHOO.widget.Record} Record object. */ getRecord : function(record) { var i; if(record instanceof widget.Record) { for(i=0; i<this._records.length; i++) { if(this._records[i] && (this._records[i]._sId === record._sId)) { return record; } } } else if(lang.isNumber(record)) { if((record > -1) && (record < this.getLength())) { return this._records[record]; } } else if(lang.isString(record)) { for(i=0; i<this._records.length; i++) { if(this._records[i] && (this._records[i]._sId === record)) { return this._records[i]; } } } // Not a valid Record for this RecordSet return null; }, /** * Returns an array of Records from the RecordSet. * * @method getRecords * @param index {Number} (optional) Recordset position index of which Record to * start at. * @param range {Number} (optional) Number of Records to get. * @return {YAHOO.widget.Record[]} Array of Records starting at given index and * length equal to given range. If index is not given, all Records are returned. */ getRecords : function(index, range) { if(!lang.isNumber(index)) { return this._records; } if(!lang.isNumber(range)) { return this._records.slice(index); } return this._records.slice(index, index+range); }, /** * Returns a boolean indicating whether Records exist in the RecordSet at the * specified index range. Returns true if and only if a Record exists at each * index in the range. * @method hasRecords * @param index * @param range * @return {Boolean} true if all indices are populated in the RecordSet */ hasRecords : function (index, range) { var recs = this.getRecords(index,range); for (var i = 0; i < range; ++i) { if (typeof recs[i] === 'undefined') { return false; } } return true; }, /** * Returns current position index for the given Record. * * @method getRecordIndex * @param oRecord {YAHOO.widget.Record} Record instance. * @return {Number} Record's RecordSet position index. */ getRecordIndex : function(oRecord) { if(oRecord) { for(var i=this._records.length-1; i>-1; i--) { if(this._records[i] && oRecord.getId() === this._records[i].getId()) { return i; } } } return null; }, /** * Adds one Record to the RecordSet at the given index. If index is null, * then adds the Record to the end of the RecordSet. * * @method addRecord * @param oData {Object} An object literal of data. * @param index {Number} (optional) Position index. * @return {YAHOO.widget.Record} A Record instance. */ addRecord : function(oData, index) { if(lang.isObject(oData)) { var oRecord = this._addRecord(oData, index); this.fireEvent("recordAddEvent",{record:oRecord,data:oData}); return oRecord; } else { return null; } }, /** * Adds multiple Records at once to the RecordSet at the given index with the * given object literal data. If index is null, then the new Records are * added to the end of the RecordSet. * * @method addRecords * @param aData {Object[]} An object literal data or an array of data object literals. * @param index {Number} (optional) Position index. * @return {YAHOO.widget.Record[]} An array of Record instances. */ addRecords : function(aData, index) { if(lang.isArray(aData)) { var newRecords = [], idx,i,len; index = lang.isNumber(index) ? index : this._records.length; idx = index; // Can't go backwards bc we need to preserve order for(i=0,len=aData.length; i<len; ++i) { if(lang.isObject(aData[i])) { var record = this._addRecord(aData[i], idx++); newRecords.push(record); } } this.fireEvent("recordsAddEvent",{records:newRecords,data:aData}); return newRecords; } else if(lang.isObject(aData)) { var oRecord = this._addRecord(aData); this.fireEvent("recordsAddEvent",{records:[oRecord],data:aData}); return oRecord; } else { return null; } }, /** * Sets or replaces one Record to the RecordSet at the given index. Unlike * addRecord, an existing Record at that index is not shifted to preserve it. * If no index is specified, it adds the Record to the end of the RecordSet. * * @method setRecord * @param oData {Object} An object literal of data. * @param index {Number} (optional) Position index. * @return {YAHOO.widget.Record} A Record instance. */ setRecord : function(oData, index) { if(lang.isObject(oData)) { var oRecord = this._setRecord(oData, index); this.fireEvent("recordSetEvent",{record:oRecord,data:oData}); return oRecord; } else { return null; } }, /** * Sets or replaces multiple Records at once to the RecordSet with the given * data, starting at the given index. If index is not specified, then the new * Records are added to the end of the RecordSet. * * @method setRecords * @param aData {Object[]} An array of object literal data. * @param index {Number} (optional) Position index. * @return {YAHOO.widget.Record[]} An array of Record instances. */ setRecords : function(aData, index) { var Rec = widget.Record, a = lang.isArray(aData) ? aData : [aData], added = [], i = 0, l = a.length, j = 0; index = parseInt(index,10)|0; for(; i < l; ++i) { if (typeof a[i] === 'object' && a[i]) { added[j++] = this._records[index + i] = new Rec(a[i]); } } this.fireEvent("recordsSetEvent",{records:added,data:aData}); // Backward compatibility for bug 1918245 this.fireEvent("recordsSet",{records:added,data:aData}); if (a.length && !added.length) { } return added.length > 1 ? added : added[0]; }, /** * Updates given Record with given data. * * @method updateRecord * @param record {YAHOO.widget.Record | Number | String} A Record instance, * a RecordSet position index, or a Record ID. * @param oData {Object} Object literal of new data. * @return {YAHOO.widget.Record} Updated Record, or null. */ updateRecord : function(record, oData) { var oRecord = this.getRecord(record); if(oRecord && lang.isObject(oData)) { // Copy data from the Record for the event that gets fired later var oldData = {}; for(var key in oRecord._oData) { if(lang.hasOwnProperty(oRecord._oData, key)) { oldData[key] = oRecord._oData[key]; } } oRecord._oData = oData; this.fireEvent("recordUpdateEvent",{record:oRecord,newData:oData,oldData:oldData}); return oRecord; } else { return null; } }, /** * @method updateKey * @deprecated Use updateRecordValue */ updateKey : function(record, sKey, oData) { this.updateRecordValue(record, sKey, oData); }, /** * Sets given Record at given key to given data. * * @method updateRecordValue * @param record {YAHOO.widget.Record | Number | String} A Record instance, * a RecordSet position index, or a Record ID. * @param sKey {String} Key name. * @param oData {Object} New data. */ updateRecordValue : function(record, sKey, oData) { var oRecord = this.getRecord(record); if(oRecord) { var oldData = null; var keyValue = oRecord._oData[sKey]; // Copy data from the Record for the event that gets fired later if(keyValue && lang.isObject(keyValue)) { oldData = {}; for(var key in keyValue) { if(lang.hasOwnProperty(keyValue, key)) { oldData[key] = keyValue[key]; } } } // Copy by value else { oldData = keyValue; } oRecord._oData[sKey] = oData; this.fireEvent("keyUpdateEvent",{record:oRecord,key:sKey,newData:oData,oldData:oldData}); this.fireEvent("recordValueUpdateEvent",{record:oRecord,key:sKey,newData:oData,oldData:oldData}); } else { } }, /** * Replaces all Records in RecordSet with new object literal data. * * @method replaceRecords * @param data {Object || Object[]} An object literal of data or an array of * data object literals. * @retur
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -