Self-referencing SQL table is a table that has ID -> ParentID relation to itself. One such example is the Employees table from the Northwind sample database (EmployeeID -> ReportsTo). You can have any number of nested self-referencing relations using only two grids.

Just set the HierarchySettings.HierarchyMode property of the parent grid to "Parent" and to "ParentAndChild" for the second grid.

Then, hook the client-side ClientSideEvents.SubGridRowExpanded event of both grids and call a special javascript function, which is autogenerated by child grids and is called showSubGrid_{GridID}, where {GridID} is the ID of the child grid, e.g. showSubGrid_ParentEmployeeGrid

It's as simple as that, this will in essense trigger the sever-side OnDataRequesting of the grid and you can get the ID of the parent row and bind the child grid accordingly.

Complete hierarchy is achieved in this example with just 2 lines of code - 1 javascript and 1 C# (check the View and Controller tabs for details).
@model MVCDemo.Models.SelfReferencingModel
@using Trirand.Web.Mvc
@using MVCDemo.Models

<!DOCTYPE html>
<html lang="en-us">
    <meta charset="utf-8">
    <title>jqGrid for ASP.NET MVC - Self-Referencing Hierarchy</title>    
    <!-- jQuery runtime minified -->
    <script src="~/Scripts/jquery-3.2.1.min.js" type="text/javascript"></script>
    <!-- The jqGrid localization file we need, English in this case -->
    <script type="text/javascript" src="~/Scripts/trirand/i18n/grid.locale-en.js"></script>
    <!-- The jqGrid client-side javascript -->
    <script type="text/javascript" src="~/Scripts/trirand/jquery.jqGrid.min.js"></script>

    <!-- The jQuery UI theme that will be used by the grid. -->
    <link rel="stylesheet" type="text/css" href="" />
    <!-- The jQuery UI theme extension jqGrid needs -->    
    <link rel="stylesheet" type="text/css" href="~/Content/themes/ui.jqgrid.css" />
        @Html.Trirand().JQGrid(Model.EmployeesGridParent, "EmployeesGrid")        
        @Html.Trirand().JQGrid(Model.EmployeesGridChild, "EmployeesGridChild")        
    <br /><br />
    <script type="text/javascript">               
        function showSubGrid(subgrid_id, row_id) 
            // the "showSubGrid_EmployeesGrid" function is autogenerated and available globally on the page by the second child grid. 
            // Calling it will place the child grid below the parent expanded row and will call the OnDataRequesting event 
            // of the child grid, with ID equal to the ID of the parent expanded row
            showSubGrid_EmployeesGridChild(subgrid_id, row_id);

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using MVCDemo.Models;
using Trirand.Web.Mvc;

namespace MVCDemo.Controllers.Grid
    public partial class GridController : Controller
        // This is the default action for the View. Use it to setup your grid Model.
        public ActionResult HierarchySelfReferencing()
            // Get the model (setup) of the grid defined in the /Models folder.
            var model = new SelfReferencingModel();

            // Pass the custmomized grid model to the View
            return View(model);
        public JsonResult HierarchySelfReferencing_ParentEmployeesDataRequested()
            // 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 NorthwindDataContext();
            var model = new SelfReferencingModel();

            return model.EmployeesGridParent.DataBind(northWindModel.Employees);

        // parentRowID is automatically passed from the parent grid to the child grid. Note: parentRowID is case sensitive
        public JsonResult HierarchySelfReferencing_ChildEmployeesDataRequested(int parentRowID)
            // 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 NorthwindDataContext();
            var model = new SelfReferencingModel();
            var employees = from e in northWindModel.Employees                            
                            where e.ReportsTo == parentRowID
                            select e;

            return model.EmployeesGridChild.DataBind(employees);

        public void HierarchySelfReferencing_SetUpGrid(SelfReferencingModel model)
            var employeesGridParent = model.EmployeesGridParent;
            var employeesGridChild = model.EmployeesGridChild;

            employeesGridParent.DataUrl = Url.Action("HierarchySelfReferencing_ParentEmployeesDataRequested");
            employeesGridParent.HierarchySettings.HierarchyMode = HierarchyMode.Parent;
            employeesGridParent.ClientSideEvents.SubGridRowExpanded = "showSubGrid";

            employeesGridChild.DataUrl = Url.Action("HierarchySelfReferencing_ChildEmployeesDataRequested");
            employeesGridChild.HierarchySettings.HierarchyMode = HierarchyMode.ParentAndChild;
            employeesGridChild.ClientSideEvents.SubGridRowExpanded = "showSubGrid";            
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" />