📄 table.js
字号:
}, this); // reindex row ids for (var i = rowId, j = this.rowCount - 1; i < j; i++) { this.columns[0][i].row.store('id', i); } } row.destroy(); delete this.rows[ rowName ]; this.rowCount--; }, /* Function: setValues Set values for given row Arguments: rowName - (string) row name / id rowOptions - (object) row specific options */ setValues: function(rowName, rowOptions) { var row = this.rows[ rowName ]; if (!row) { return; } // custom class, remove previous in case something has changed row.className = this.options.classPrefix + 'TRow'; if (rowOptions.cls) { row.addClass(rowOptions.cls); } // table rows are clickable and this row is not disabled var rowClickable = this.options.click && !rowOptions.noclick; var rowId = row.retrieve('id'); row.retrieve('cells', []).each(function(cellObj, cellId) { var cellValue = '', origValue = '', cellClickable = this.columnClick[ cellId ] !== null ? true : rowClickable; cellOptions = rowOptions.cells[ cellId ]; // only a value is passed if ($type(cellOptions) != 'object') { origValue = cellOptions; } // other options passed else { origValue = cellOptions.value || ''; // custom class, remove previous in case something has changed if (cellObj.cell.className != cellOptions.cls) { cellObj.cell.className = cellOptions.cls; } if (cellOptions.title) { cellObj.cell.set('title', cellOptions.title); } cellClickable = !cellOptions.noclick; cellObj.cell.store('options', cellOptions); } // callback for cell value, highest priority if (this.callbacks[ cellId ]) { cellValue = this.callbacks[ cellId ](origValue); } // translate cell value else if (this.translate[ cellId ]) { cellValue = FlashSYS.translate(this.options.trPrefix + origValue); } // leave it as it is else { cellValue = origValue; } // (un)clickable class checks cellObj.cell.addClass(this.options.classPrefix + (cellClickable ? 'Clickable' : 'UnClickable')); if (this.options.sortable) { this.columns[ cellId ][ rowId ] = { 'row': row, 'value': origValue }; } cellObj.txt.set('text', cellValue); }, this); row.store('options', rowOptions); }, /* Function: initColumnCache Initialize column cache, only used for sorting */ initColumnCache: function() { if (!this.options.sortable) { return; } this.columns = []; for (var i = 0; i < this.columnCount; i++) { this.columns[i] = []; } }, /* Function: initHead Initialize head elements, this is only done once */ initHead: function() { $each(this.options.tableHead, function(cellOptions, cellName){ var cell = new Element('div', { 'id': this.idPrefix + 'thead_' + cellName, 'styles': { 'width': cellOptions.width.toString() + '%' } }).inject(this.tableHead); // add text element and translate its value if blank was not specified var cellTxt = new Element('span').inject(cell); if (!cellOptions.blank) { cellTxt.set('text', FlashSYS.translate(this.options.trPrefix + cellName)); } // cache cell width and get id var cellId = this.cellWidth.push(cellOptions.width) - 1; // default sorting on init if (cellName === this.options.sortBy) { this.sortId = cellId; } cell.store('options', { 'id': cellId, 'name': cellName, 'axis': $pick(cellOptions.axis, 'string') // axis for sorting }); // save cell to local cache this.headCells.push( cell ); // save callback and translate this.callbacks.push( cellOptions.callback ); this.translate.push( !!cellOptions.translate ); // custom class if (cellOptions.cls) { cell.addClass(cellOptions.cls); } // click function for column if (cellOptions.click) { this.columnClick.push({ 'click': cellOptions.click, 'params': cellOptions.params, 'confirm': cellOptions.confirm }); } // no click, but has params - default to FlashSYS.load else if (cellOptions.params) { this.columnClick.push({ 'click': $load, 'params': cellOptions.params, 'confirm': cellOptions.confirm }); } // no function, just pad the array else { this.columnClick.push(null); } // add click event for sortable cell that are not blank if (this.options.sortable && !cellOptions.blank) { cell.addClass(this.options.classPrefix + 'Sortable').addEvent('click', this.doSort.bind(this, cell) ); } this.columnCount++; }, this); this.initColumnCache(); this.addClearer(this.tableHead); }, /* Function: doSort Sort table by given column Arguments: column - (element) clicked head cell / column */ doSort: function(column) { var options = column.retrieve('options'); var fn = '_cmp' + options.axis.capitalize(); if (this.sortId >= 0) { this.headCells[ this.sortId ].removeClass(this.options.classPrefix + 'SortAsc').removeClass(this.options.classPrefix + 'SortDesc'); } var injectPos = 'bottom'; // already sorting by this column - invert if (this.sortId == options.id) { this.sortAsc = !this.sortAsc; injectPos = this.sortAsc ? 'bottom' : 'top'; } else { this.sortAsc = true; this.sortId = options.id; } column.addClass(this.options.classPrefix + (this.sortAsc ? 'SortAsc' : 'SortDesc')); // sort array and re-insert elements $A( this.columns[ options.id ] ).sort( this[ fn ] ).each(function(cell){ cell.row.inject(this.tableBody, injectPos); }, this); }, /* Function: _cmpNumber Int / float comparison Arguments: objA - (object) first object to compare objB - (object) second object to compare Returns: comparison result (integer) */ _cmpNumber: function(objA, objB) { if (objA.value == undefined) { return -1; } else if (objB.value == undefined) { return 1; } else { return objA.value.toFloat() - objB.value.toFloat(); } }, /* Function: _cmpNumber String comparion Arguments: objA - (object) first object to compare objB - (object) second object to compare Returns: comparison result (integer) */ _cmpString: function(objA, objB) { if (objA.value == undefined) { return -1; } else if (objB.value == undefined) { return 1; } else if (objA.value == objB.value) { return 0; } else if (objA.value > objB.value) { return 1; } else { return -1; } }, /* Function: _cmpNumber Add clearing div (usually between table rows) Arguments: injectTo - (object) parent for clearing div Returns: clearing div element */ addClearer: function(injectTo) { return new Element('div', { 'class': this.options.classPrefix + 'Clearer' }).inject(injectTo); }});
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -