-
26 Jun 2011 10:46 AM #1
How to set custom icon for tree node in ExtJS 4?
How to set custom icon for tree node in ExtJS 4?
I cannot figure this out.
Even demo examples with custom icons on screenshot are now actually all with standard icons.
How to set custom icon for a tree node?
-
26 Jun 2011 7:46 PM #2
I use good old fashion CSS overrides for Hub List. Here is my css file.
PHP Code:/* Replaces default tree node yellow
folder icon with an OSX style one
*/
#containerTreePanel .x-tree-icon-parent {
background-image: url("images/icon-fldr-default-closed.png");
}
/* This is the open state of the yellow
folder icon.
*/
#containerTreePanel .x-grid-tree-node-expanded .x-tree-icon-parent {
background-image: url("images/icon-fldr-default-closed.png");
padding-top: 1px;
}
/* Replaces the default tree node leaf
icon with Hub List list icon
*/
#containerTreePanel .x-tree-icon-leaf {
background-image: url("images/icon-sdbar-list.png");
width: 14px;
}
Last edited by bergstyle; 26 Jun 2011 at 7:47 PM. Reason: fixed typos
-
13 Jul 2011 2:21 AM #3
We got solution from Evan Trimboli.
It's rather simple:
node.set('iconCls', your-icon-class);
-
6 Aug 2011 11:17 PM #4
You can do this while defining the store:
and your css class:Code:{ text: "Some text", expanded: true, iconCls: 'ico-test', children: [ ] }
Code:.ico-test { background-color:#352788; width:15px; height:15px; background-image:none !important; }
-
7 Aug 2011 4:05 AM #5
-
8 Aug 2011 2:11 AM #6
-
24 Aug 2011 3:29 AM #7
I found that if you do like this
"children": [{
"text": "Go jogging",
"leaf": true,
"checked": true,
"iconCls":"sys-car"
},{
You get the Resulttreepanel.png
-
21 Nov 2011 3:03 AM #8
expanded/not expanded nodes
expanded/not expanded nodes
To have expanded/not expanded nodes keep your icon you can add .x-tree-lines before your class selector in your css.
If you set the node's iconCls property to node-icon, add the following to your css and it works wether or not the node is expanded :
Code:.x-tree-lines img.node-icon{ width:16px; background-image:url('/resources/images/admin-user.png') }
-
21 Nov 2011 3:29 AM #9Ext JS Premium Member
- Join Date
- Apr 2008
- Location
- Groningen - Netherlands
- Posts
- 1,010
- Vote Rating
- 23
just put this model on your tree and the icon property on the node will work. In that case css classes are not needed.
Code:Ext.define('TreeModel', { extend: 'Ext.data.Model', fields: [ { name: 'text', type: 'string', defaultValue: null }, { name: 'parentId', type: 'string', defaultValue: null }, { name: 'index', type: 'int', defaultValue: null }, { name: 'depth', type: 'int', defaultValue: 0 }, { name: 'expanded', type: 'bool', defaultValue: false, persist: false }, { name: 'expandable', type: 'bool', defaultValue: true, persist: false }, { name: 'checked', type: 'auto', defaultValue: null }, { name: 'leaf', type: 'bool', defaultValue: false, persist: false }, { name: 'cls', type: 'string', defaultValue: null, persist: false }, { name: 'icon', type: 'string', defaultValue: null, persist: false }, { name: 'iconCls', type: 'string', defaultValue: null, persist: false }, { name: 'iconQtip', type: 'string', defaultValue: null, persist: false }, { name: 'root', type: 'boolean', defaultValue: false, persist: false }, { name: 'isLast', type: 'boolean', defaultValue: false, persist: false }, { name: 'isFirst', type: 'boolean', defaultValue: false, persist: false }, { name: 'allowDrop', type: 'boolean', defaultValue: true, persist: false }, { name: 'allowDrag', type: 'boolean', defaultValue: true, persist: false }, { name: 'loaded', type: 'boolean', defaultValue: false, persist: false }, { name: 'loading', type: 'boolean', defaultValue: false, persist: false }, { name: 'href', type: 'string', defaultValue: null, persist: false }, { name: 'hrefTarget', type: 'string', defaultValue: null, persist: false }, { name: 'qtip', type: 'string', defaultValue: null, persist: false }, { name: 'qtitle', type: 'string', defaultValue: null, persist: false } ] });
-
31 Dec 2011 12:48 AM #10


Reply With Quote