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

📄 cellselection.js

📁 javascript 很酷的类库
💻 JS
📖 第 1 页 / 共 3 页
字号:
				selectionRowNums[selectionRowNums.length] = i;				break;			}		}	}	return selectionRowNums;},getSelectionColNums : function () {	var selectionColNums = [],		allRowSelections = [],		colSelectionFlags = isc.CellSelection.COL_SELECTION_FLAGS,		numRowChunks = Math.ceil(this.numCols/32),         rows = this.data,         numRows = rows.length,         rowSelection;		// bitwise-OR the selection flags for every row into allRowSelections	for (var i = 0; i < numRows; i++) {			// get selection property for the current row		rowSelection = rows[i][this.selectionProperty];		if (!rowSelection) continue;				// iterate through chunks in this row		for (var j = 0, numColsInChunk; j < numRowChunks; j++) {			// if any selection flags are set, bitwise-OR with selection flags for all previous rows			if (rowSelection[j]) {				allRowSelections[j] = allRowSelections[j] | rowSelection[j];			}		}	}	// if no selections, return now	if (allRowSelections.length == 0) return selectionColNums;		// compare allRowSelections flags against each constant in colSelectionFlags	// to determine which columns have a selected cell	for (var i = 0, numCols = this.numCols; i < numCols; i++) {		if ((allRowSelections[Math.floor(i/32)] & colSelectionFlags[i%32]) != 0)			selectionColNums[selectionColNums.length] = i;	}		return selectionColNums;},getSelectionBounds : function () {	var rows = this.getSelectionRowNums(),		cols = this.getSelectionColNums();	return [rows.first(), cols.first(), rows.last(), cols.last()];},//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//~~~~~ Selection Setters (internal) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//>	@method	cellSelection._setCellSelection()// Select or deselect a particular cell.  All other selection routines call this one.// <p>// This method:<pre>// - Initializes row selection property if none.// - Saves cell coordinates in this.lastSelectedCell if selection state of//   this cell changes.// - Marks selection as dirty if selection state of this cell changes.// </pre>////		@param	rowNum		(number)	number of row//		@param	colNum		(number)	number of column//		@param	newState	(boolean)	desired selection state for this cell	// 	//		@return				(boolean)	true if selection state of this cell is changed,//										false otherwise// @visibility internal//<_setCellSelection : function (rowNum, colNum, newState) {	var row = this.data[rowNum],		rowSelection = (row ? row[this.selectionProperty] : null),		rowChunkNum = Math.floor(colNum/32),		rowChunkSelection = (rowSelection ? rowSelection[Math.floor(colNum/32)] : 0),		colSelectionFlag = isc.CellSelection.COL_SELECTION_FLAGS[colNum%32];	// if the row or column does not exist, return false	if (!row || colNum > this.numCols - 1) return false;		// if the row is not enabled, return false	if (row.enabled == false) return false;	// if the row has no selection property, initialize it now	if (rowSelection == null) {		rowSelection = row[this.selectionProperty] = [];		for (var i = 0, numChunks = Math.ceil(this.numCols/32); i < numChunks; i++) rowSelection[i] = 0;	}	// if this chunk in the row has no selection flags yet, initialize them now	// NOTE: this will only happen if numCols is changed without throwing away this selection...would this ever happen?	else if (rowChunkSelection == null) {		rowSelection[rowChunkNum] = 0;	}	// if the cell's selection state is already set to the new state, return false	if (((rowChunkSelection & colSelectionFlag) != 0) == newState) return false;		// cell exists, is enabled, and has a different state; so change the state via bitwise XOR	rowSelection[rowChunkNum] = rowChunkSelection ^ colSelectionFlag;	// if selecting, remember that this is the last selected cell	if (newState) this.lastSelectedCell = [rowNum, colNum];		// mark the cached selection as dirty	this._dirty = true;	// return true to indicate that the cell's state was actually changed	return true;},setCellRangeSelection : function (startRowNum, startColNum, endRowNum, endColNum, newState) {    this.changedCells =         this._setCellRangeSelection(startRowNum, startColNum, endRowNum, endColNum, newState); 	return this._cellSelectionsChanged();},// returns array of [rowNum,colNum] arrays representing cells whose selection state was actually// changed_setCellRangeSelection : function (startRowNum, startColNum, endRowNum, endColNum, newState) {	var changedCells = [],		minRowNum, maxRowNum, minColNum, maxColNum;	if (startRowNum <= endRowNum) {		minRowNum = startRowNum;		maxRowNum = endRowNum;	} else {		minRowNum = endRowNum;		maxRowNum = startRowNum;	}		if (startColNum <= endColNum) {		minColNum = startColNum;		maxColNum = endColNum;	} else {		minColNum = endColNum;		maxColNum = startColNum;	}    //>DEBUG    if (this.logIsDebugEnabled()) {        this.logDebug((newState ? "selecting " : "deselecting ") +                       [minRowNum, minColNum] + " through " + [maxRowNum, maxColNum]);    }    //<DEBUG	for (var rowNum = minRowNum; rowNum <= maxRowNum; rowNum++) {		for (var colNum = minColNum; colNum <= maxColNum; colNum++) {			if (this._setCellSelection(rowNum, colNum, newState)) {				changedCells[changedCells.length] = [rowNum, colNum];            }        }    }	return changedCells;},//	sets this.changedCells//	calls this.selectionChanged()setCellListSelection : function (cellList, newState) {	if (!cellList) return false;	var changedCells = [];		for (var i = 0, length = cellList.length, rowNum, colNum; i < length; i++) {		rowNum = cellList[i][0];		colNum = cellList[i][1];		if (this._setCellSelection(rowNum, colNum, newState))			changedCells[changedCells.length] = [rowNum, colNum];	}	this.changedCells = changedCells;		return this._cellSelectionsChanged();},//	helper called by a bunch of other methods_cellSelectionsChanged : function () {	if (this.changedCells.length > 0) {		this.selectionChanged();		return true;	} else		return false;},//>	@method	cellSelection.selectionChanged()//  Observable handler fired whenever the cell selection is modified//		@group	selection//// @visibility internal// @group selection//<selectionChanged : function () {},//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//~~~~~ Selection Setters (public) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~setCellSelection : function (rowNum, colNum, newState) {	if (this._setCellSelection(rowNum, colNum, newState)) {		this.changedCells = [[rowNum, colNum]];		this.selectionChanged();		return true;	} else		return false;},//>	@method	cellSelection.selectCell()//			Select a particular cell//		@group	selection////		@param		rowNum  (number)	row index of cell to select//      @param      colNum  (number)    column index of cell to select//		@return				(boolean)	true == selection actually changed, false == no change//  @visibility Analytics//<selectCell : function (rowNum, colNum) {	return this.setCellSelection(rowNum, colNum, true);},//>	@method	cellSelection.deselectCell()//			Deselect a particular cell//		@group	selection////		@param		rowNum	(number)	row index of the cell to select//      @param      colNum  (number)    column index of the cell to select//		@return				(boolean)	true == selection actually changed, false == no change//  @visibility Analytics//<deselectCell : function (rowNum, colNum) {	return this.setCellSelection(rowNum, colNum, false);},selectCellRange : function (startRowNum, startColNum, endRowNum, endColNum) {	this.changedCells = this._setCellRangeSelection(startRowNum, startColNum, endRowNum, endColNum, true);	return this._cellSelectionsChanged();},deselectCellRange : function (startRowNum, startColNum, endRowNum, endColNum) {	this.changedCells = this._setCellRangeSelection(startRowNum, startColNum, endRowNum, endColNum, false);	return this._cellSelectionsChanged();},//	simply setting the selectionProperty for each row to 0 or ~0 would seem a//	good shortcut in the following methods, but this wouldn't tell us//	exactly which cells have changed--and setting the style of a cell unnecessarily//	is ~really~ expensiveselectRow : function (rowNum) {	return this.selectCellRange(rowNum, 0, rowNum, this.numCols-1);},deselectRow : function (rowNum) {	return this.deselectCellRange(rowNum, 0, rowNum, this.numCols-1);},selectCol : function (colNum) {	return this.selectCellRange(0, colNum, this.data.length-1, colNum);},deselectCol : function (colNum) {	return this.deselectCellRange(0, colNum, this.data.length-1, colNum);},selectAll : function () {	return this.selectCellRange(0, 0, this.data.length-1, this.numCols-1);},deselectAll : function () {	return this.deselectCellRange(0, 0, this.data.length-1, this.numCols-1);},//>	@method	cellSelection.selectCellList()//			select an array of cells//		@group	selection//		@param		list	(array[])	Array of cells to select. Each cell can be specified//                                      as a 2 element array <code>[rowNum, colNum]</code>//		@return				(boolean)	true == selection actually changed, false == no change//  @visibility Analytics//<selectCellList : function (cellList) {	return this.setCellListSelection(cellList, true);},//>	@method	cellSelection.deselectCellList()//			deselect an array of cells////		@group	selection//		@param		list	(array[])	Array of cells to deselect. Each cell can be specified//                                      as a 2 element array <code>[rowNum, colNum]</code>//		@return				(boolean)	true == selection actually changed, false == no change//  @visibility Analytics//<deselectCellList : function (cellList) {	return this.setCellListSelection(cellList, false);},//>	@method	cellSelection.selectSingleCell()//			select a single cell and deselect everything else//		@group	selection//		@param		rowNum (number) row index of cell to select//      @param      colNum  (number)    column index of cell to select//		@return				(boolean)	true == selection actually changed, false == no change//  @visibility Analytics//<selectSingleCell : function (rowNum, colNum) {	//	remember whether this cell was selected before we deselect all cells	var cellWasSelected = this.cellIsSelected(rowNum, colNum);	//	deselect all cells, using the helper method so we don't call selectionChanged() yet	this.changedCells = this._setCellRangeSelection(0, 0, this.data.length-1, this.numCols-1, false);		//	select this cell	this._setCellSelection(rowNum, colNum, true);		//	if this cell wasn't selected before, add it to changedCells	if (!cellWasSelected)		this.changedCells[this.changedCells.length] = [rowNum, colNum];	// XXX else remove it from changedCells...	return this._cellSelectionsChanged();},selectSingleRow : function (rowNum) {	var changedCells = [];		// deselect rows before this one	if (rowNum > 0)		changedCells = this._setCellRangeSelection(0, 0, rowNum-1, this.numCols-1, false);	// select this row	changedCells = changedCells.concat(this._setCellRangeSelection(rowNum, 0, rowNum, this.numCols-1, true));		// deselect rows after this one	if (rowNum < this.data.length-1)

⌨️ 快捷键说明

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