HT for Web TreeView Manual

Index


Overview

The HT for Web provides the tree table component class ht.widget.TreeView, which displays the parent-child relationship tree structure of the Data type object in the Datamodel, supporting sorting and filtering functions.

Through treeView = new ht.widget.TreeView(dataModel); initialize a tree component object, dataModel parameter is a data model bound to a tree component, the model will create a new data model for binding inside the tree component constructor when its null.

TreeView Component

The main configurable properties and functions of the tree component class ht.widget.TreeView are as follows:

The following code sets the expand and collapse toggle icon, overloading the treeView.getIcon function to implement node expansion and merging to display different icon effects

treeView.setExpandIcon('images/expand.gif');
treeView.setCollapseIcon('images/collapse.gif');
treeView.getIcon = function (data) {
    if(data.a('class')){
        return 'images/class.png';
    }else{
        if (this.isExpanded(data)) {
            return 'images/dir-open.gif';
        } else {
            return 'images/dir.gif';
        }                        
    }
};

The following code sets the sort function through treeView.setSortFunc to achieve the sort of implementation of the same type before package appears in the class type

treeView.setSortFunc(function(d1, d2){
    if(d1.a('class') && !d2.a('class')){
        return 1;
    }
    if(!d1.a('class') && d2.a('class')){
        return -1;
    }
    return d1.getName().localeCompare(d2.getName());
}); 

The checkData function selects the entity, and the more current checkMode affects the relevant datas' selected; setFocusData will make the data still have the selected focus effect in the checkMode mode; makeVisible will enable the treeView component to expand and scroll to the visible effect to the specified data.

var data = dataModel.getDataByTag('ht.widget.TreeView');
treeView.checkData(data);
treeView.setFocusData(data);
treeView.makeVisible(data); 

This example overloads the treeView.handleDragAndDrop function, set the click of the selected data in the prepare phase through the treeView.sm().ss(data);, begin stage will be a rectangular color background div component is added to the document.body, moving the div component in the between phase and eventually creating the corresponding Node data to GraphView component in the end phase and deleting the document.body div component to complete the drag-and-drop process.

treeView.handleDragAndDrop = function(e, state){
    var data;
    if(state === 'prepare'){
        data = treeView.getDataAt(e);
        treeView.sm().ss(data);
        if(data && data.getIcon() === 'color'){
            if(!currentDiv){
                currentDiv = ht.Default.createElement('div');
                currentDiv.style.width = size + 'px';
                currentDiv.style.height = size + 'px';
            }
            currentDiv.style.background = data.getName();                                
        }
    }
    else if(state === 'begin'){
        if(currentDiv){
            var pagePoint = ht.Default.getPagePoint(e);
            currentDiv.style.left = pagePoint.x - size/2 + 'px';
            currentDiv.style.top = pagePoint.y - size/2 + 'px';
            document.body.appendChild(currentDiv);
        }
    }
    else if(state === 'between'){
        if(currentDiv){
            var pagePoint = ht.Default.getPagePoint(e);
            currentDiv.style.left = pagePoint.x - size/2 + 'px';
            currentDiv.style.top = pagePoint.y - size/2 + 'px';
        }
    }
    else{
        if(currentDiv){                            
            if(ht.Default.containedInView(e, graphView)){     
                var node = new ht.Node();
                node.setSize(30, 30);
                node.setPosition(graphView.lp(e));
                node.s({
                    'select.type': 'circle',
                    'shape': 'circle',
                    'shape.background': currentDiv.style.background,
                    'shape.gradient': 'radial.center'
                });
                graphView.dm().add(node);
            }
            document.body.removeChild(currentDiv);
            currentDiv = null;                            
        }
    }
};

This example uses graphView.getView().style.background = '#FCFCFC'; to set the background color and draw a text hint at the bottom through graphView.addBottomPainter:

graphView.getView().style.background = '#FCFCFC';
graphView.addBottomPainter(function(g){
    ht.Default.drawText(g, 'Drag tree node to drop here ..', '24px Arial', 'lightgray', 50, 100, 0, 0, 'left');
});

Welcome to contact us service@hightopo.com