Go Back   SmartClient Forums > Addendums
Wiki Register Search Today's Posts Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 23rd Apr 2010, 12:35
Isomorphic Isomorphic is offline
Administrator
 
Join Date: May 2006
Posts: 38,663
Default 70rc2 feature/patch - customize separateFolders to show folders after leaves

In 7.0rc2, the TreeGrid separateFolders property is documented as follows:
Quote:
Specifies whether folders and leaves should be segregated in the treeGrid display. With separateFolders:true and sortDirection:"descending", folders are displayed before their sibling leaves; with sortDirection:"ascending", leaves are displayed before their sibling folders.
This is actually incorrect -- when separateFolders is true and sortDirection is descending, folders are shown after their sibling leaves, not before.
Moreover the ability to customize this behavior is useful for applications where a user may want folders to show up before their sibling leaves, but for the sort direction to be descending.
In addition to this in 7.0rc2, separateFolders has no effect if the grid is entirely unsorted. While not a bug, we have decided that this is unexpected behavior and that grids should respect separateFolders even if the grid isn't explicitly sorted.

In the SmartClient 8.0 codebase we've made the following changes in this area:

separateFolders is now respected on grids with no explicit sort.

A new property 'sortFoldersBeforeLeaves' has been introduced, which may be set on the TreeGrid, or on the Tree or ResultTree object directly.
If true (the default) folders will show before leaves when the sortDirection specified for the tree is Array.ASCENDING (and after leaves when the sort direction is descending). If false, that behavior will be reversed.


This patch code applies these 2 changes to SmartClient version 7.0rc2, allowing you to customize the separateFolders behavior by setting sortFoldersBeforeLeaves to true or false on your TreeGrid, or Tree data object.


Code:
if (window.isc) {
    
    if (isc.version.startsWith("7.0rc2")) {

        isc.TreeGrid.addProperties({
                setData : function (_1, _2, _3, _4) {
                    this.invokeSuper(isc.TreeGrid, "setData", _1, _2, _3, _4);
                    if (!this.data) {
                        return;
                    }
                    this.data.separateFolders = this.separateFolders;
                    if (this.sortFoldersBeforeLeaves != null) {
                        this.data.sortFoldersBeforeLeaves = this.sortFoldersBeforeLeaves;
                    }
                    if (this.showRoot && isc.ResultTree && 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;
                    this.data.openDisplayNodeType = this.displayNodeType;
                }
        });
        isc.Tree.addProperties({
                getChildren:function (_1, _2, _3, _4, _5, _6) {
                    if (_3 == null && this.$27i == null && this.separateFolders) {
                        this.sortByProperty();
                    }
                
                    if (_1 == null) {
                        _1 = this.root;
                    }
                    if (this.isLeaf(_1)) {
                        return null;
                    }
                    if (_1[this.childrenProperty] == null) {
                        var _7 = [];
                        _1[this.childrenProperty] = _7;
                        return _7;
                    }
                    var _8 = _1[this.childrenProperty], _9;
                    if (_5) {
                        _9 = [];
                        for (var i = 0, _11 = _8.length; i < _11; i++) {
                            var _12 = _8[i];
                            if (this.fireCallback(_5, "node,parent,tree", [_12, _1, this])) {
                                _9[_9.length] = _12;
                            }
                        }
                        _8 = _9;
                    }
                    if (_2 == isc.Tree.FOLDERS_ONLY) {
                        _9 = [];
                        for (var i = 0, _11 = _8.length; i < _11; i++) {
                            if (this.isFolder(_8[i])) {
                                _9[_9.length] = _8[i];
                            }
                        }
                    } else if (_2 == isc.Tree.LEAVES_ONLY) {
                        _9 = [];
                        for (var i = 0, _11 = _8.length; i < _11; i++) {
                            if (this.isLeaf(_8[i])) {
                                _9[_9.length] = _8[i];
                            }
                        }
                    } else {
                        _9 = _8;
                    }
                    if (_3) {
                        _9.sortByProperty(this.sortProp, _4, _3, _6);
                    }
                    return _9;
                },
                
                sortFoldersBeforeLeaves:true,
                $27n:function () {
                    var _1 = this.sortProp, _2 = this.sortDirection, _3 = this.separateFolders != false;
                    var _4 = isc.SB.create();
                    _4.append("var __tree__ = ", this.getID(), ";\rvar value = '';");
                    
                    if (_3) {
                         var folderPrefix, leafPrefix;
                         if (this.sortFoldersBeforeLeaves) {
                             folderPrefix = "0:";
                             leafPrefix = "1:";
                         } else {
                             folderPrefix = "1:";
                             leafPrefix = "0:";
                         }
                         _4.append("value+=(__tree__.isFolder(obj) ? '" + folderPrefix +
                                                            "' : '" + leafPrefix + "');");
                    }
                    if (_1 && _1 != "title") {
                        _4.append("var prop = obj['", _1, "'];", "if (isc.isA.Number(prop)) prop = prop.stringify(12);", "if (isc.isA.Date(prop)) prop = prop.getTime();", "if (prop != null) value += prop + ':';");
                    }
                    if (_1) {
                        _4.append("var title = __tree__.getTitle(obj);", "if (isc.isA.Number(title)) title = title.stringify(12);", "if (isc.isA.Date(title)) title = title.getTime();", "if (title != null) {title = title + ''; value += title.toLowerCase()}");
                    }
                    _4.append("return value;");
                    this.addMethods({$27i: new Function("obj,property", _4.toString())});
                }
        });
        

    } else {
        isc.Log.logWarn("Patch code for SmartClient version 7.0RC2 included in this application. " +
            "You are running version:" + isc.version + ". This patch code will have no effect " +
            "and can be removed.");
    }
}
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search


© 2010,2011 Isomorphic Software. All Rights Reserved