Selection


Selection


CheckBoxes


You can perform many tasks such as expand, collapse, toggle, check, uncheck, select, unselect, etc on the client-side using the clients-side API. To get the client-side instance (object) of the treeview, get it's jQuery selector using its client-side ID and call the getClientSideInstance() method. The method will return the treeview client-side instance which you can later use to call many client-side API methods. Please, refer to the ASPX tab on this example for code details.
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="default.aspx.cs" Inherits="JQSuiteASPNETExample.examples.tree.clientapi._default" %>
<%@ Register Assembly="Trirand.Web" TagPrefix="trirand" Namespace="Trirand.Web.UI.WebControls" %>

<!DOCTYPE html>
<html lang="en">
<head id="Head1" runat="server">
    <meta charset="utf-8">
    <title>jqTreeView for ASP.NET WebForms - Client-Side API</title>
    <!-- The jQuery UI theme that will be used by the treeview  -->
    <link rel="stylesheet" type="text/css" media="screen" href="http://ajax.aspnetcdn.com/ajax/jquery.ui/1.10.3/themes/redmond/jquery-ui.css" />
    <!-- The jQuery UI theme extension jqTreeView needs -->
    <link rel="stylesheet" type="text/css" media="screen" href="/themes/ui.jqtreeview.css" />
    <!-- jQuery runtime minified -->
    <script src="http://ajax.microsoft.com/ajax/jquery/jquery-2.0.3.min.js" type="text/javascript"></script>    
    <!-- The jqTreeView client-side javascript -->
    <script src="/js/trirand/jquery.jqTreeView.min.js" type="text/javascript"></script>    
    <style type="text/css">    
        body, html { font-size: 80%; }    
    </style>
</head>

<body>
    <form id="form1" runat="server">
    
    <table>
        <tr>
            <td valign="top">
               <trirand:JQTreeView 
                    runat="server" 
                    ID="JQTreeView1" 
                    CheckBoxes="true"
                    Width="200"
                    Height="300">
                    <Nodes>
                        <trirand:JQTreeNode Text="One" />
                        <trirand:JQTreeNode Text="Two" Expanded="true">
                            <Nodes>
                                <trirand:JQTreeNode Text="2.1" />
                                <trirand:JQTreeNode Text="2.2" Expanded="true">
                                    <Nodes>
                                        <trirand:JQTreeNode Text="2.2.1" Value="London" />
                                        <trirand:JQTreeNode Text="2.2.2" />
                                        <trirand:JQTreeNode Text="2.2.3" />
                                    </Nodes>
                                </trirand:JQTreeNode>
                                <trirand:JQTreeNode Text="2.3" />
                            </Nodes>
                        </trirand:JQTreeNode>
                        <trirand:JQTreeNode Text="Three" />
                    </Nodes>
                </trirand:JQTreeView>             
            </td>
            <td valign="top">
                <fieldset title="Selection">
                    <legend style="font-size:120%; font-family: Tahoma">Selection</legend>
                    <input type="button" value="Select Nodes" onclick="selectNodes()" />
                    <input type="button" value="Unselect '2.2.3'" onclick="unSelectNode()" />
                    <input type="button" value="Unselect All" onclick="unSelectAllNodes()" />
                </fieldset>
                <br /><br />
                <fieldset title="Expand/Collapse">
                    <legend style="font-size:120%; font-family: Tahoma">Selection</legend>
                    <input type="button" value="Expand All Nodes" onclick="expandAllNodes()" />
                    <input type="button" value="Collapse All Nodes" onclick="collapseAllNodes()" />
                    <br />
                    <input type="button" value="Expand 'Two'" onclick="expandNode()" />
                    <input type="button" value="Collapse 'Two'" onclick="collapseNode()" />
                    <input type="button" value="Toggle 'Two'" onclick="toggleNode()" />
                </fieldset>
                 <br /><br />
                <fieldset title="Checkboxes">
                    <legend style="font-size:120%; font-family: Tahoma">CheckBoxes</legend>
                    <input type="button" value="Check All Nodes" onclick="checkAllNodes()" />
                    <input type="button" value="Uncheck All Nodes" onclick="unCheckAllNodes()" />
                    <br />
                    <input type="button" value="Check 'Two'" onclick="checkNode()" />
                    <input type="button" value="Uncheck 'Two'" onclick="unCheckNode()" />                    
                </fieldset>
            </td>
        </tr>
    </table>
    
    <script type="text/javascript"> 
    
    
    function selectNodes() {
        var tree = $("#JQTreeView1").getTreeViewInstance();
        var node = tree.getNodeByText("Two");
        if (node)
            tree.select(node);
        
        var node = tree.getNodeByValue("London");        
        if (node)
            tree.select(node);
        
        var node = tree.getNodeByText("2.2.3");
        if (node)
            tree.select(node);
    }
    
    function unSelectNode() {
        var tree = $("#JQTreeView1").getTreeViewInstance();
        var node = tree.getNodeByText("2.2.3");
        if (node)
            tree.unSelect(node);
    }
    
    function unSelectAllNodes() {
        var tree = $("#JQTreeView1").getTreeViewInstance();
        tree.unSelectAll();
    }
    
    function expandNode() {
        var tree = $("#JQTreeView1").getTreeViewInstance();
        var node = tree.getNodeByText("Two");
        if (node)
            tree.expand(node);
    }
    
    function collapseNode() {
        var tree = $("#JQTreeView1").getTreeViewInstance();
        var node = tree.getNodeByText("Two");
        if (node)
            tree.collapse(node);
    }
    
    function toggleNode() {
        var tree = $("#JQTreeView1").getTreeViewInstance();
        var node = tree.getNodeByText("Two");
        if (node)
            tree.toggle(node);
    }
    
    function expandAllNodes() {
        var tree = $("#JQTreeView1").getTreeViewInstance();
        tree.expandAll();
    }
    
    function collapseAllNodes() {
        var tree = $("#JQTreeView1").getTreeViewInstance();
        tree.collapseAll();
    }
    
    function checkNode() {
        var tree = $("#JQTreeView1").getTreeViewInstance();
        var node = tree.getNodeByText("Two");
        if (node)
            tree.check(node);
    }
    
    function unCheckNode() {
        var tree = $("#JQTreeView1").getTreeViewInstance();
        var node = tree.getNodeByText("Two");
        if (node)
            tree.unCheck(node);
    }
    
    function checkAllNodes() {
        var tree = $("#JQTreeView1").getTreeViewInstance();
        var allNodes = tree.getAllNodes();
        $.each(allNodes, function(index, node) {
            tree.check(node);
        });
    }
    
    function unCheckAllNodes() {
        var tree = $("#JQTreeView1").getTreeViewInstance();
        var allNodes = tree.getAllNodes();
        $.each(allNodes, function(index, node) {
            tree.unCheck(node);
        });
    }
    
    </script>
    
    <br />
    <br />
    <trirand:codetabs runat="server" ID="tabs"></trirand:codetabs>
    </form>
</body>
</html>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace JQSuiteASPNETExample.examples.tree.clientapi
{
    public partial class _default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
    }
}
Switch theme:


Theming is based on the very popular jQuery ThemeRoller standard. This is the same theming mechanism used by jQuery UI and is now a de-facto standard for jQuery based components. The benefits of using ThemeRoller are huge. We can offer a big set of ready to use themes created by professional designers, including Windows-like themes (Redmond), Apple-like theme (Cupertino), etc. In addition to that any jQuery UI controls on the same page will pick the same theme.

Last, but not least, you can always roll your own ThemeRoller theme, using the superb Theme Editor

To use a theme, simply reference 2 Css files in your Html <head> section - the ThemeRoller theme you wish to use, and the jqGrid own ThemeRoller Css file. For example (Redmond theme):

<link rel="stylesheet" type="text/css" media="screen" href="/themes/redmond/jquery-ui-1.8.2.custom.css" />
<link rel="stylesheet" type="text/css" media="screen" href="/themes/ui.jqgrid.css" />