开发者

Forcing vertical scrollbar re-calcuation in a hierarchical tree class derived from mx.controls.Tree

I'm working (for my sins) on a Flex 3.3 project, which unfortunately cannot be upgraded to a newer SDK version at this stage, and have hit an issue with the custom hierarchical tree class (subclassing mx.controls.Tree) we're using. Excuse the spelling; t开发者_StackOverflow中文版he previous developer had a fear of dictionaries...

public class HierachyTree extends Tree

public function HierachyTree()
{
    super();
    iconFunction = itemIconFunc;
    // etc.
}

I'm using a solution somewhere between these two methods (basically, implementing ITreeDataDescriptor) in order to add live text filtering to the component, and it's working so far:

public class HierachyTreeFilteredDataDescriptor implements ITreeDataDescriptor
{
    private var filter:Function

    public function HierachyTreeFilteredDataDescriptor(filterFunction:Function)
    {
        this.filter = filterFunction;
    }

    public function getChildren(node:Object, model:Object=null):ICollectionView
    {
        var children:ArrayCollection = new ArrayCollection([]);
        // Filter the children...
        return children;
    }

    public function hasChildren(node:Object, model:Object=null):Boolean
    {
        var treeItem:Object = node as Object;

        if (! (treeItem is ScenarioMeta)) return (treeItem as Object).children.length > 0;
        else return false;
    }

The issue is that (with tree:HierachyTree) neither tree.maxVerticalScrollPosition nor the protected property tree.verticalScrollBar.maxScrollPosition updates when the search string is changed.

I've tried calling invalidateList() and invalidateDisplayList() on tree — and calling invalidateDisplayList() and invalidateSize() on tree.verticalScrollBar — to no avail.

Any ideas?


I have completely the same situation. I have a need to filter the whole tree, and I did use the solution from those 2 blogs. Tried to validateList(), validateDisplayList(), tried to return a new collection(not filtered) on getChildren in data descriptor, but that caused other issues. The following was the easiest and worked for me the best:

treeDataProvider.dispatchEvent(new CollectionEvent(CollectionEvent.COLLECTION_CHANGE, false, false, CollectionEventKind.RESET));


So, let me get this straight, what you're trying to accomplish is filter the data as per a search string inserted which should then refresh the tree?

If that's the case, it's fairly simple as long as you're using ArrayCollection as the data provider for the tree:

// Check if data is ArrayCollection
var ac:ArrayCollection;
if(tree.dataProvider is ArrayCollection)
{
   ac = ArrayCollection(tree.dataProvider);
}
else if(tree.dataProvider is HierarchicalData) // Check if it's hierarchical data
{
   ac = HierarchicalData(tree.dataProvider).source as ArrayCollection;
}

// filter - specify custom filter function somewhere, look at docs on how to implement
ac.filterFunction = someFilterFunction; 
ac.refresh(); // Does the filtering and lets the tree know that it should redraw all nodes

I think you get the idea. Much easier to do this based on the data.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜