jqGrid supports tree-grid mode, where you can display rows of data of the same structure (column definition)
as hierarchial tree structure. In your model, just set the TreeGridSettings.Enabled property to true
and the grid will be assuming tree-mode response from the server (see the Model code tab for details).
This means that in addition to the row data, you need to return data that will help jqGrid determine the hierarchy of the rows.

When selecting rows, you need to specify some or all of the following reserved fields

  • tree_level - the level of the row in the tree hierarchy. 0 is for root row.

  • tree_leaf - if the row is leaf (no child rows). This will make it non-expandable and will have an alternative icon.

  • tree_expanded - if the row is expanded by default or not.

  • tree_parent - the primary key (ID) of the parent row (only applicable for child rows)

  • tree_loaded - true/false - if the tree nodes are already loaded. Can be used to show several levels expanded by default.


You can also control the different images per grid rows - in expanded, collapsed and leaf states. This can be achieved with the following properties available from the TreeGridSettings collection - ExpandedIcon, CollapsedIcon, LeafIcon
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="default.aspx.cs" Inherits="JQSuiteASPNETExample.examples.grid.treegrid.simpletree._default" %>
<%@ Register Assembly="Trirand.Web" TagPrefix="trirand" Namespace="Trirand.Web.UI.WebControls" %>

<!DOCTYPE html>
<html lang="en-us">
<head id="Head1" runat="server">
    <meta charset="utf-8">
    <title>jqGrid for ASP.NET WebForms - TreeGrid - simple tree</title>
    <!-- The jQuery UI theme that will be used by the grid -->
    <link rel="stylesheet" type="text/css" media="screen" href="http://code.jquery.com/ui/1.12.1/themes/redmond/jquery-ui.css" />
    <!-- The jQuery UI theme extension jqGrid needs -->
    <link rel="stylesheet" type="text/css" media="screen" href="/themes/ui.jqgrid.css" />
    <!-- jQuery runtime minified -->
    <script src="/js/jquery-3.2.1.min.js" type="text/javascript"></script>    
    <!-- The localization file we need, English in this case -->
    <script src="/js/trirand/i18n/grid.locale-en.js" type="text/javascript"></script>
    <!-- The jqGrid client-side javascript -->
    <script src="/js/trirand/jquery.jqGrid.min.js" type="text/javascript"></script>    
    
        
    <style type="text/css">    
        body, html { font-size: 80%; }         
        .ui-jqgrid tr.jqgrow td  { border: 0px none;} 
        .ui-jqgrid-htable,
        .ui-jqgrid-hbox { visibility: hidden }    
    </style>
</head>


<body>
    <form id="form1" runat="server">
        
    <trirand:JQGrid runat="server" ID="SimpleTree" Width="600px" Height="350px">
        <Columns>
            <trirand:JQGridColumn DataField="ID" PrimaryKey="True" Visible="false" />
            <trirand:JQGridColumn DataField="Name" Width="590" />            
        </Columns>
        <TreeGridSettings Enabled="true" />
        <ToolBarSettings ToolBarPosition="Hidden" />
        <ClientSideEvents GridInitialized="formatGrid" />
    </trirand:JQGrid>
    
    <br /><br />
    
    <trirand:codetabs runat="server" id="tabs"></trirand:codetabs> 
    
        <script type="text/javascript">
    
        function formatGrid()
        {
            $('.ui-jqgrid-htable','.ui-jqgrid-hbox').hide();
            $('tr.jqgrow td').css({'border':'0px none'});
        }
    
    </script> 
    
    </form>
</body>
</html>


using JQSuiteASPNETExample.dbml;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.UI.WebControls;

namespace JQSuiteASPNETExample.examples.grid.treegrid.simpletree
{
    public partial class _default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            // Get both the grid Model and the data Model
            // The data model in our case is an autogenerated linq2sql database based on Northwind.            
            var northWindModel = new NorthWindDataClassesDataContext();

            //JQGridTreeExpandData expandData = grid.GetTreeExpandData();

            // ********************************************************************************************
            // when selecting rows, you need to specify some or all of the following reserved fields
            // tree_level - the level of the row in the tree hierarchy. 0 is for root row.
            // tree_leaf - if the row is leaf (no child rows). This will make it non-expandable and will have an alternative icon
            // tree_expanded - if the row is expanded by default or not
            // tree_parent - the primary key (ID) of the parent row (only applicable for child rows)
            // tree_loaded - true/false - if the tree nodes are already loaded. Can be used to show several levels expanded by default.
            // ********************************************************************************************


            // Get all grid rows in a cached List of the underlying type (RetailData).
            List cachedGridRows = (from product in northWindModel.RetailDatas
                                               select product).ToList();

            // Use the cache to calculate tree_loaded, tree_parent, tree_level, tree_leaf and tree_expanded
            var hierarchyRows = from product in cachedGridRows
                                select new
                                {
                                    ID = product.ID,
                                    Name = product.Name,
                                    Price = product.Price,
                                    Color = product.Color,
                                    Quantity = product.Quantity,
                                    ParentID = product.ParentID,
                                    tree_loaded = true,
                                    tree_parent = product.ParentID,
                                    tree_level = GetRowLevel(product.ParentID, cachedGridRows),
                                    tree_leaf = LoadAllRowsCollapsed_IsLeafRow(product.ID, cachedGridRows),
                                    tree_expanded = true
                                };

            SimpleTree.DataSource = hierarchyRows;
            SimpleTree.DataBind();
        }

        private int GetRowLevel(int? parentID, List cachedGridRows)
        {
            int level = 0;
            while (parentID != null)
            {
                level++;
                var result = from product in cachedGridRows
                             where product.ID == parentID
                             select product;

                parentID = result.Single().ParentID;
            }

            return level;
        }

        private bool LoadAllRowsCollapsed_IsLeafRow(int? productID, List cachedGridRows)
        {
            foreach (RetailData retailData in cachedGridRows)
            {
                if (retailData.ParentID == productID)
                {
                    return false;
                }
            }

            return true;
        }
    }
}
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" />