typescriptazure-devopsvssdk

How do I get vss sdk treeview to collapse by default?


How can I get a combo control of type TreeView.ComboTreeBehaviorName to have its nodes collapsed by default?

I've tried looking at the documentation here and here, but it seems completely unhelpful to me.

I've also tried inspecting the types (in vss.d.ts) to see if there's a property I can set:

Here are some relevant code excerpts:

import * as Controls_Combos from "VSS/Controls/Combos";
import * as Controls from "VSS/Controls";
import * as TreeView from "VSS/Controls/TreeView";



 this._$areaInput = $("<input type='text' id='inputAreaPicker' />")
                .val(someValueThatDoesnotMatter)
                .bind("blur", (e) => {
                    this._updateSomeOtherField();
                    this._validate();
                });
}

...

        <Controls_Combos.Combo>Controls.Enhancement.enhance(
            Controls_Combos.Combo,
            this._$areaInput,
            <Controls_Combos.IComboOptions> {
                type: TreeView.ComboTreeBehaviorName,
                source: ConvertToTreeNodes(someItems),  // loads multi-level tree successfully
                mode: 'drop',
                allowEdit: false,
                maxAutoExpandDropWidth: 1, // seems to have no effect
                collapsed: true  // no effect
            }
        );


export function ConvertToTreeNodes(items): TreeView.TreeNode[] {
    // let _this = this;
    return $.map(items, function (item) {
        let node = new TreeView.TreeNode(item.name);
        node.id = item.id;
        if (item.children && item.children.length > 0) {
            node.addRange(ConvertToTreeNodes(item.children));
        }
        node.expanded = false;
        return node;
    });
}

Solution

  • The answer is an undocumented property called 'treeLevel':

    <Controls_Combos.Combo>Controls.Enhancement.enhance(
                Controls_Combos.Combo,
                this._$areaInput,
                <Controls_Combos.IComboOptions> {
                    type: TreeView.ComboTreeBehaviorName,
                    source: ConvertToTreeNodes(someItems),
                    mode: 'drop',
                    allowEdit: false,
                    treeLevel: 0 // collapse to first level by default
    
                }
            );
    

    I've requested that it be documented