📄 treegrid.js
字号:
} var root = tree.getRoot(), openState = []; this._addNodeToOpenState(tree, root, openState); return isc.Comm.serialize(openState);}, _addNodeToOpenState : function (tree, node, openState) { if (!tree.isOpen(node) || !tree.isLoaded(node)) return false; var children = tree.getFolders(node), hasOpenChildren = false; if (children != null) { for (var i = 0; i < children.length; i++) { hasOpenChildren = this._addNodeToOpenState(tree, children[i], openState) || hasOpenChildren; } } openState[openState.length] = tree.getPath(node); return true;}, //> @method treeGrid.setOpenState() // Reset this set of open folders within this grid's data to match the // +link{type:treeGridOpenState} object passed in.<br>// Used to restore previous state retrieved from the grid by a call to // +link{treeGrid.getOpenState()}.//// @param openState (treeGridOpenState) Object describing the desired set of open folders.// @group viewState// @see treeGrid.getOpenState()// @visibility external//<setOpenState : function (openState) { openState = this.evalViewState(openState, "openState") if (!openState) return; if (!this.data) { this.logWarn("unable to set open state for this treeGrid as this.data is unset"); return; } this.data.closeAll(); this.data.openFolders(openState);},//> @method treeGrid.getSelectedPaths() // Returns a snapshot of the current selection within this treeGrid as // a +link{type:listGridSelectedState} object.<br>// This object can be passed to +link{treeGrid.setSelectedPaths()} to reset this grid's selection// the current state (assuming the same data is present in the grid).<br>// @group viewState// @see treeGrid.setSelectedPaths();// @visibility external// @return (listGridSelectedState) current state of this grid's selection//<getSelectedPaths : function () { if (!this.selection) return null; var selection = this.selection.getSelection() || [], selectedPaths = []; // store paths only. for (var i = 0; i < selection.length; i++) { selectedPaths[i] = this.data.getPath(selection[i]); } return isc.Comm.serialize(selectedPaths);},//> @method treeGrid.setSelectedPaths() // Reset this grid's selection to match the +link{type:listGridSelectedState} object passed in.<br>// Used to restore previous state retrieved from the grid by a call to // +link{treeGrid.getSelectedPaths()}.//// @group viewState// @param selectedPaths (listGridSelectedState) Object describing the desired selection state of// the grid// @see treeGrid.getSelectedPaths()// @visibility external//<setSelectedPaths : function (selectedPaths) { selectedPaths = this.evalViewState(selectedPaths, "selectedPaths") if (!selectedPaths) return; var selection = this.selection, data = this.data; if (data && selection) { selection.deselectAll(); var nodes = []; // use find to look up node by path for (var i = 0; i < selectedPaths.length; i++) { var node = data.find(selectedPaths[i]); if (node) nodes.add(node); } this.selection.selectList(nodes); }},//> @type treeGridViewState // An object containing the "view state" information for a treeGrid. In addition to the // state data contained by a +link{type:listGridViewState} object, this will also contain the // current open state of the treeGrid in question.<br>// Note that this object is not intended to be interrogated directly, but may be stored // (for example) as a blob on the server for view state persistence across sessions.// // @group viewState// @visibility external//<// treeGridViewState object is implemented as a simple JS object containing the following // fields:// - selected [an (undocumented) treeGridSelectedState object - an array of selected nodes' paths]// - field [a listGridFieldState object]// - sort [a listGridSortState object]// - open [a treeGridOpenState object]//> @method treeGrid.getViewState() // Overridden to return a +link{type:treeGridViewState} object for the grid.// @return (treeGridViewState) current view state for the grid.// @group viewState// @see type:treeGridViewState// @see treeGrid.setViewState();// @visibility external//< getViewState : function () { var state = this.Super("getViewState", [true]); state.open = this.getOpenState(); return "(" + isc.Comm.serialize(state) + ")";}, //> @method treeGrid.setViewState() // Overridden to take a +link{type:treeGridViewState} object.//// @param viewState (treeGridViewState) Object describing the desired view state for the grid// @group viewState// @see treeGrid.getViewState()// @visibility external//< setViewState : function (state) { // Ensure we set open state after setting sort state this.Super("setViewState", arguments); // don't bother warning on error - Super() will have done that already state = this.evalViewState(state, "viewState", true) if (!state) return; if (state.open) this.setOpenState(state.open);},// if data is not specified, use an empty Tree.getDefaultData : function () { // NOTE: initializing to a ResultTree would effectively trigger fetch on draw. Don't want // to do this unless fetchData() is called (possibly via autoFetchData property), in which // case the empty starter Tree will be discarded and replaced by a ResultTree //if (this.dataSource) return this.createResultTree(); return isc.Tree.create();},//> @method treeGrid.setData()// Set the +link{class:Tree} object this TreeGrid will view and manipulate.//// @param newData (Tree) Tree to show// @visibility external//<setData : function (newData,a,b,c) { this.invokeSuper(isc.TreeGrid, "setData", newData,a,b,c); if (!this.data) return; // set the separateFolders and showRoot options of the tree as well this.data.separateFolders = this.separateFolders; if (this.showRoot && isc.isA.ResultTree(this.data)) { this.logWarn("showRoot may not be set with a databound treeGrid, unexpected " + "results may occur"); } this.data.showRoot = this.showRoot; // should we show only branches or leaves this.data.openDisplayNodeType = this.displayNodeType;},draw : function (a,b,c,d) { if (this.initialData && !isc.isA.ResultSet(this.data)) { this.setData(this.createResultTree()); } this.invokeSuper(isc.TreeGrid, "draw", a,b,c,d);},bodyConstructor:"TreeGridBody",// Override bodyKeyPress to handle open and closing of trees// Note: standard windows behavior with Left and Right arrow key presses in a treeGrid is:// - multiple selection seems to *always* be disallowed, so doesn't come into play// - arrow right on a closed folder will open the folder// - arrow right on an open folder (with content) will move selection to the first child node// - arrow left on an open folder will close the folder// - arrow left on a node within a folder will move selection to the node's parent folderbodyKeyPress : function (event) { // if exactly one record is selected, mimic windows LV behaviors for arrow left and right var selection = this.selection; if (this.selectionType != isc.Selection.NONE && this.data.getLength() > 0 && selection.anySelected() && !selection.multipleSelected()) { var node = this.selection.getSelectedRecord(); if (event.keyName == "Arrow_Left") { if (this.data.isFolder(node) && this.data.isOpen(node)) { this.closeFolder(node); } else { this._generateRecordClick(this.data.getParent(node), true); } return false; } else if (event.keyName == "Arrow_Right") { if (this.data.isFolder(node)) { if (!this.data.isOpen(node)) { this.openFolder(node); return false; } else { var nextNode = this.getRecord(this.data.indexOf(node) + 1); if (nextNode != null && this.data.getParent(nextNode) == node) { this._generateRecordClick(nextNode, true); return false; } } } } } return this.Super("bodyKeyPress", arguments); },// fire synthetic context menu events for nodes_cellContextClick : function (record, recordNum, fieldNum) { if (recordNum < 0 || fieldNum < 0) return true; // not in body, allow native context menu var isFolder = this.data.isFolder(record); // fire synthetic context click events. Note any of these can cancel further processing by // returning an explicit false, which presumably indicates they've shown a context menu if (this.nodeContextClick && this.nodeContextClick(this, record, recordNum) == false) { return false; } if (isFolder) { if (this.folderContextClick && this.folderContextClick(this, record, recordNum) == false) { return false; } } else { if (this.leafContextClick && this.leafContextClick(this, record, recordNum) == false) { return false; } } // fire the superclass implementation of this method to fire 'cellContextClick', if defined, // and show the default context menu if appropriate return this.Super("_cellContextClick", arguments); },//> @method treeGrid.handleEditCellEvent()// @group event handling // Override handleEditCellEvent to not allow editing if the click / doubleClick event // occurred over the open area of the treeGrid//// @return (boolean) false == cancel further event processing//<handleEditCellEvent : function (recordNum, fieldNum) { var record = this.getRecord(recordNum); // if they're clicking in the open area of the list, don't allow editing to proceed if (this.clickInOpenArea(record)) return false; // return the results of a call to the superclass method return this.Super("handleEditCellEvent",arguments);},//> @method treeGrid.canEditCell() // Overridden to disallow editing of the +link{treeNode.name, name} field of this grid's data// tree. Also disallows editing of the auto-generated tree field, which displays the result// of +link{method:Tree.getTitle} on the node.// @return (boolean) Whether to allow editing this cell// @visibility external//<canEditCell : function (rowNum, colNum) { if (this.Super("canEditCell", arguments) == false) return false; if (this.getField(colNum)[this.fieldIdProperty] == this.data.nameProperty) return false; if (this.getField(colNum)[this.fieldIdProperty] == this._titleField) return false; return true;},// Override the method to determine the widths of the form items displayed while editing to// account for the tree-field indentsgetEditFormItemFieldWidths : function (record) { var level = this.data.getLevel(record); if (!this.showRoot) level--; var indentSize = level * this.indentSize; indentSize += this.iconSize + this.getOpenerIconSize(record); if (this.getExtraIcon(record)) indentSize += this.iconSize;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -