MVC5 Classic
Use Custom Node Icons

wijtree allows you to use custom icons to mark the tree nodes. You can also switch icons based on a node's current state. See the Node Icons > Tree sample of the MVC Control Explorer live demos at http://demo.componentone.com/ASPNET/MVCExplorer/tree/Icons.

  1. Create an C1 ASP.NET MVC 5 Web Application.
  2. In the Solution Explorer, expand the Views | Shared folder and double-click _Layout.cshtml to open the file.
  3. Add the following markup within the <body> tags of the page.
    <div>
            <ul id="tree">
                <li class="folder"><a><span>Folder 1</span></a>
                    <ul>
                        <li class="folder"><a><span>Folder 1.1</span></a>
                            <ul>
                                <li class="file"><a><span>File 1.1</span></a></li>
                                <li class="file"><a><span>File 1.2</span></a></li>
                                <li class="file"><a><span>File 1.3</span></a></li>
                                <li class="file"><a><span>File 1.4</span></a></li>
                                <li class="file"><a><span>File 1.5</span></a></li>
                            </ul>
                        </li>
                        <li class="file"><a><span>File 1.2</span></a></li>
                        <li class="file"><a><span>File 1.3</span></a></li>
                        <li class="file"><a><span>File 1.4</span></a></li>
                        <li class="file"><a><span>File 1.5</span></a></li>
                    </ul>
                </li>
                <li class="folder"><a><span>Folder 2</span></a>
                    <ul>
                        <li class="file"><a><span>File 2.1</span></a></li>
                        <li class="file"><a><span>File 2.2</span></a></li>
                        <li class="file"><a><span>File 2.3</span></a></li>
                        <li class="file"><a><span>File 2.4</span></a></li>
                        <li class="file"><a><span>File 2.5</span></a></li>
                    </ul>
                </li>
                <li class="folder"><a><span>Folder 3</span></a>
                    <ul>
                        <li class="file"><a><span>File 3.1</span></a></li>
                        <li class="file"><a><span>File 3.2</span></a></li>
                        <li class="file"><a><span>File 3.3</span></a></li>
                        <li class="file"><a><span>File 3.4</span></a></li>
                        <li class="file"><a><span>File 3.5</span></a></li>
                    </ul>
                </li>
            </ul>
        </div>
    
  4. Add the following script to initialize the widget.
    <script id="scriptInit" type="text/javascript">
            $(document).ready(function () {
                $("#tree").wijtree();
                $("li.folder").wijtreenode("option", "collapsedIconClass", "ui-icon-folder-collapsed")
                    .wijtreenode("option", "expandedIconClass", "ui-icon-folder-open");
                $("li.file").wijtreenode("option", "itemIconClass", "ui-icon-document");
            });      
        </script>
    
  5. Run your program. When you click on a node, observe how the file icon changes. It should resemble the following image.

 

 


Copyright (c) GrapeCity, inc. All rights reserved.

Product Support Forum |  Documentation Feedback