Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7576269
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T16:52:47+00:00 2026-05-30T16:52:47+00:00

I have a deep tree and for user it’s difficult to distinguish the levels.

  • 0

I have a deep tree and for user it’s difficult to distinguish the levels. Is it possible to have custom css-classes for each level? For example firstlike h1 and bold, second bold …

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T16:52:48+00:00Added an answer on May 30, 2026 at 4:52 pm

    I find the question interesting, but I think that one can better use individual icons for the tree nodes. If you do need to set CSS style per row I can you forward to the answer and this one. You should just change the test criteria in the demos to test the content of the hidden level column.

    So I created the demo which demonstrate how you can set individual icons per node level:

    enter image description here

    First of all I should mention, that TreeGrid supports individual icons for leafs out-of-the-box. You can just add icon property to the posted data. The value of the property should be the CSS class which will be added to the div which represent the icon. For example icon: "ui-icon-star". The standard class for the icon is “ui-icon-radio-off”. Additionally the div receive the classes “ui-icon tree-leaf treeclick”. So if you find the icon which you need in the standard jQuery UI icons the changing if the icon of the leaf will be very easy.

    Non-leaf tree nodes have two icons: one in the collapsed form and another in the expanding form. There are no simple way to change the icons per jqGrid configuration, but you can implement the requirement by writing an additional JavaScript code inside of loadComplete and with respect of chaining (overwriting or subclassing) of expandNode and collapseNode method like I suggested here.

    In the demo I just changed the icons of the top-level tree nodes. In the same way you can change icons on any other level. Below you find the most important parts of the code from my demo:

    var $grid = $("#treegrid"),
        orgExpandNode = $.fn.jqGrid.expandNode,
        orgCollapseNode = $.fn.jqGrid.collapseNode;
    
    $grid.jqGrid({
        ....
        loadComplete: function (data) {
            var item, i, l = data.length || 0;
            for (i = 0; i < l; i++) {
                item = data[i];
                if (!item.isLeaf && (item.level === "0" || item.level === 0)) {
                    if (item.expanded) {
                        $("#" + item.id + " div.treeclick")
                            .removeClass("ui-icon-triangle-1-s")
                            .addClass("ui-icon-carat-1-s");
                    } else {
                        $("#" + item.id + " div.treeclick")
                            .removeClass("ui-icon-triangle-1-e")
                            .addClass("ui-icon-carat-1-e");
                    }
    
                }
            }
        }
    });
    
    $.jgrid.extend({
        expandNode: function (rc) {
            var ret = orgExpandNode.call(this, rc);
            if (!rc.isLeaf && (rc.level === "0" || rc.level === 0)) {
                $("#" + rc._id_ + " div.treeclick")
                    .removeClass("ui-icon-triangle-1-s ui-icon-carat-1-e")
                    .addClass("ui-icon-carat-1-s");
            }
            return ret;
        },
        collapseNode: function (rc) {
            var ret = orgCollapseNode.call(this, rc);
            if (!rc.isLeaf && (rc.level === "0" || rc.level === 0)) {
                $("#" + rc._id_ + " div.treeclick")
                    .removeClass("ui-icon-triangle-1-e ui-icon-carat-1-s")
                    .addClass("ui-icon-carat-1-e");
            }
            return ret;
        }
    });
    

    UPDATED: I thought a little more about the problem of tree icons and modified the code to the new demo.

    I decided that it would be more practicable to be able to define icons of the tree node exactly like for the leafs. Because one need to specify two icons one can separate the classes for collapsed and expanded icons by comma. For example: icon: "ui-icon-carat-1-e,ui-icon-carat-1-s". The code can be rewritten to the following:

    var $grid = $("#treegrid"),
        orgExpandNode = $.fn.jqGrid.expandNode,
        orgCollapseNode = $.fn.jqGrid.collapseNode,
        changeTreeNodeIcon = function (item) {
            var icons, $div, id;
            if (!item.isLeaf && typeof item.icon === "string") {
                icons = item.icon.split(',');
                if (icons.length === 2) {
                    id = item[this.p.localReader.id] || item[this.p.jsonReader.id];
                    $div = $("#" + $.jgrid.jqID(id) + " div.treeclick");
                    if (item.expanded) {
                        $div.removeClass(icons[0])
                            .removeClass("ui-icon-triangle-1-s")
                            .addClass(icons[1]);
                    } else {
                        $div.removeClass(icons[1])
                            .removeClass("ui-icon-triangle-1-e")
                            .addClass(icons[0]);
                    }
                }
            }
        };
    
    $grid.jqGrid({
        ....
        loadComplete: function (data) {
            var item, i, l = data.length || 0;
            for (i = 0; i < l; i++) {
                item = data[i];
                changeTreeNodeIcon.call(this, item);
            }
        }
    });
    
    $.jgrid.extend({
        expandNode: function (rc) {
            var ret = orgExpandNode.call(this, rc);
            changeTreeNodeIcon.call(this[0], rc);
            return ret;
        },
        collapseNode: function (rc) {
            var ret = orgCollapseNode.call(this, rc);
            changeTreeNodeIcon.call(this[0], rc);
            return ret;
        }
    });
    

    UPDATED: I posted the feature request and the pull request which add the described above functionality to TreeGrid.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a tree data structure that is L levels deep each node has
I have a tree structure that can be n-levels deep, without restriction. That means
I'm working with some classes which, when throwing, have a relatively deep InnerException tree.
Anybody have a good example how to deep clone a WPF object, preserving databindings?
I have a hierarchy of tables 3 levels deep (QualificaionType has many QualificationGroups, which
I have a xml which is max 3 levels deep. Now by using C#
I have a product catalog. Each category consists of different number (in deep) of
I have a deep structure that I would like to display as a tree
I have a relatively deep object tree in C# that needs to be initialized
I have a tree structure in MySQL using a parent_id field for each node.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.