Results 1 to 5 of 5

Thread: Bold items on the tree

  1. #1
    Sencha User
    Join Date
    Feb 2015
    Posts
    6

    Default Bold items on the tree

    Hey, I have a problem. Is it possible to bold some items on the tree? If the answer is yes, how can I do it?

  2. #2
    Sencha User
    Join Date
    Jul 2011
    Location
    Germany
    Posts
    223

    Default

    Quote Originally Posted by piechos View Post
    Hey, I have a problem. Is it possible to bold some items on the tree? If the answer is yes, how can I do it?
    I didn't bold any items, but greyed them out. I guess you might be able to alter following code for bolding.
    Code:
    // Extension of Tree
                @Override
                protected void update() {
                    super.update();
                    for (M item : this.getStore().getAll()) {
                        // Put your condition here
                        if (item.shouldBeBold()) {
                            // Severe nullchecking is important. Soon after adding items to store, there might not be corresponding nodes. If there are nodes, there might not be Elements or they have no Style yet.
                            if (this.findNode(item) != null) {
                                if (this.getView().getIconElement(this.findNode(item)) != null && this.getView().getIconElement(this.findNode(item)).getStyle() != null) {
                                    this.getView().getIconElement(this.findNode(item)).getStyle().setOpacity(0.3);
                                }
                                if (this.getView().getTextElement(this.findNode(item)) != null && this.getView().getTextElement(this.findNode(item)).getStyle() != null) {
                                    this.getView().getTextElement(this.findNode(item)).getStyle().setOpacity(0.5);
                                }
                            }
                        }
                    }
                }

  3. #3
    Sencha User
    Join Date
    Feb 2015
    Posts
    6

    Default

    I resolved it that way:


    Code:
    final List<String> keys = getFilteredList();
    
    
    filteringTree.getTree().setCell(new AbstractCell<String>() {
    			@Override
    			public void render(Context context, String valueString,
    					SafeHtmlBuilder sb) {
    				Object key = context.getKey();
    				System.out.println(keys.contains(key));
    				if (context.getKey() != null
    						&& !context.getKey().equals("null")
    						&& valueString != null
    						&& valueString.trim().length() > 0
    						&& keys.contains(key)) {
    					sb.appendHtmlConstant("<b>" + valueString + "</b>");
    
    
    				} else {
    					sb.appendHtmlConstant(valueString);
    				}
    			}
    where getFilteredList() gets the list of elements which fit to the filter

  4. #4
    Sencha User
    Join Date
    Jul 2011
    Location
    Germany
    Posts
    223

    Default

    Quote Originally Posted by piechos View Post
    I resolved it that way:


    Code:
    final List<String> keys = getFilteredList();
    
    
    filteringTree.getTree().setCell(new AbstractCell<String>() {
                @Override
                public void render(Context context, String valueString,
                        SafeHtmlBuilder sb) {
                    Object key = context.getKey();
                    System.out.println(keys.contains(key));
                    if (context.getKey() != null
                            && !context.getKey().equals("null")
                            && valueString != null
                            && valueString.trim().length() > 0
                            && keys.contains(key)) {
                        sb.appendHtmlConstant("<b>" + valueString + "</b>");
    
    
                    } else {
                        sb.appendHtmlConstant(valueString);
                    }
                }
    where getFilteredList() gets the list of elements which fit to the filter
    Right. Using setCell() is probably the right way. I couldn't cause I wanted to alter the icon, too.

    But be careful! Depending on the source of valueString the use of sb.appendHtmlConstant(valueString); is a security threat! An attacker being able to set valueString may use this for cross-site scripting.
    And btw, as valueString is not a constant, using appendHtmlConstant seems to be odd anyway. I think it is better and safer this way:
    Code:
                sb.append(SafeHtmlUtils.fromTrustedString("<b>"));
                sb.appendEscaped(valueString);
                sb.append(SafeHtmlUtils.fromTrustedString("</b>"));

  5. #5
    Sencha User
    Join Date
    Feb 2015
    Posts
    6

    Default

    You are right, I didn't think about security. Thanks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •