Articles in this section
Category / Section

How to show dotted lines for connecting tree nodes in TreeView?

2 mins read

Show dotted lines for connecting tree 

 

We don’t have inbuild option to show the dotted lines for connecting tree node. But we can customize the TreeView to show the dotted lines. We need to add the dotted line background image for tree node. For adding the styles for particular tree view control, we can use the cssClass property. Using this cssClass we can add the custom styles, please refer the below code block.

 

[TreeView.html]

 

<div id="treeView"></div>
    
<script type="text/javascript">
        var localData = [
                   { id: 1, name: "Discover Music", hasChild: true, expanded: true },
                   { id: 2, pid: 1, name: "Hot Singles" },
                   { id: 3, pid: 1, name: "Rising Artists" },
                   { id: 4, pid: 1, name: "Live Music" },
                   { id: 6, pid: 1, name: "Best of 2013 So Far" },
                   { id: 7, name: "Sales and Events", hasChild: true, expanded: true },
                   { id: 8, pid: 7, name: "100 Albums - $5 Each" },
                   { id: 9, pid: 7, name: "Hip-Hop and R&B Sale" },
                   { id: 10, pid: 7, name: "CD Deals" },
                   { id: 11, name: "Categories", hasChild: true },
                   { id: 12, pid: 11, name: "Songs" },
                   { id: 13, pid: 11, name: "Bestselling Albums" },
                   { id: 14, pid: 11, name: "New Releases" },
                   { id: 15, pid: 11, name: "Bestselling Songs" }
            ];
 
        $(function () {
            $("#treeView").ejTreeView({
               fields: { id: "id", parentId: "pid", text: "name", hasChild: "hasChild", dataSource: localData, expanded: "expanded" },
               cssClass: 'custom'
            });
        });
 
    </script>
 

 

Need to add the following styles for TreeView control.

 

     <style type="text/css">
/* horizontal dotted image */
        .custom.e-treeview .e-item {
            background-image: url(./image/Horizontal.png);
            background-repeat: repeat-y;
        }
 
        .custom.e-treeview .e-text-wrap {
            padding-left: 4px;
        }
/* vertical dotted image */
        .custom .e-text-wrap:before {
              display: block;
              content: " ";
              background: url(./image/Vertical.png);
              height: 10px;
              position: absolute;
              width: 20px;
              margin-left: -17px;
              margin-top: 12px;
              background-repeat: repeat-x;
        }
/* minus icon */
        .custom.e-treeview .e-icon.e-minus:before {
            content: "";
            font-size: 12px;
            margin-left: 2px;
        }
/* plus icon */
        .custom.e-treeview .e-icon.e-plus:before {
            content: "";
            font-size: 12px;
            margin-left: 2px;
        }
 
        .custom.e-treeview .e-icon.e-minus, .custom.e-treeview .e-icon.e-plus{
            border: 1px solid gray;
            padding: 0px;
            display: flex;
            margin-left: -28px;
            align-items: center;
            background-color: darkgrey;
        }
 
        .e-item.last.e-collapse {
            background-repeat: no-repeat !important;
        }
        
        .custom.e-treeview .e-item.last {
            background-image: url(./image/3.png);
            background-repeat: no-repeat;
        }
    </style>
 

 

Please refer to the below link for the sample.

 

https://www.syncfusion.com/downloads/support/directtrac/general/ze/TreeDottedLine533211525

 

 

Conclusion

I hope you enjoyed learning about how to show dotted lines for connecting tree nodes in TreeView.

You can refer to our JavaScript TreeView feature tour page to know about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications.  You can also explore our JavaScript TreeView example to understand how to create and manipulate data.

For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.

If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forumsDirect-Trac, or feedback portal. We are always happy to assist you!

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please  to leave a comment
Access denied
Access denied