1. #1
    Sencha User
    Join Date
    Jan 2012
    Posts
    6
    Vote Rating
    0
    nakhli is on a distinguished road

      0  

    Question Unanswered: Chage tree icons base on node underlying data type

    Unanswered: Chage tree icons base on node underlying data type


    Hello,

    I'm using a com.sencha.gxt.widget.core.client.tree.Tree. I would like to change the icon of a node based on the tree node's underlying data (and NOT on the fact that the node is leaf or not, this is not important).

    What's the best way to achive this? I am using gxt 3.0.0 beta2 and gwtp

    Thank you!

  2. #2
    Sencha User PhiLho's Avatar
    Join Date
    Nov 2011
    Location
    Near Paris, France
    Posts
    139
    Answers
    2
    Vote Rating
    1
    PhiLho is on a distinguished road

      0  

    Default


    We use something like that:
    Code:
          someTree.setIconProvider( new IconProvider<BaseTreeNode>()
          {
             @Override
             public ImageResource getIcon( BaseTreeNode model )
             {
                if ( model.getName().endsWith( "1" ) ) return Resources.I.icon1();
                else if ( model.getName().endsWith( "2" ) ) return Resources.I.icon2();
                else if ( model.getName().endsWith( "3" ) ) return Resources.I.icon3();
                else if ( model.getName().endsWith( "4" ) ) return Resources.I.icon4();
                else return null;
             }
          } );
    The example is a bit silly, as it is just a mockup / prototype, but obviously you can use other information from the BaseTreeNode to display.

  3. #3
    Sencha User
    Join Date
    Jan 2012
    Posts
    6
    Vote Rating
    0
    nakhli is on a distinguished road

      0  

    Default


    Thank you for your response. looks good.

    How can I access the default resources of the gxt tree? I would like to use the default icons (the folder icon) bundled with gxt?

  4. #4
    Sencha User PhiLho's Avatar
    Join Date
    Nov 2011
    Location
    Near Paris, France
    Posts
    139
    Answers
    2
    Vote Rating
    1
    PhiLho is on a distinguished road

      0  

    Default


    The return null line takes care of that: in this case, the default icon is used. We still see the folders with their default look.

Thread Participants: 1

Tags for this Thread