Tree Renderer"

From Documentation
m ((via JWB))
m ((via JWB))
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
 
{{ZKDevelopersReferencePageHeader}}
 
{{ZKDevelopersReferencePageHeader}}
  
When a tree (<javadoc>org.zkoss.zul.Tree</javadoc>) is assigned with a model, a default renderer is assigned too<ref>For the concept about component, model and renderer, please refer to [[ZK_Developer's_Reference/MVC/Model/List_Model#Model-driven_Display|the Model-driven Display section]].</ref>. The default renderer will assume that each tree item has only one column, and it converts the data into a string directly<ref>If the tree is assigned a template called <tt>model</tt>, then the template will be used to render the tree. For more information, please refer to [[ZK Developer's Reference/MVC/View/Template/Tree Template|the Tree Template section]].</ref>. If you want to display multiple columns or retrieve a particular field of the data, you have to implement <javadoc type="interface">org.zkoss.zul.TreeitemRenderer</javadoc> to handle the rendering.
+
When a tree (<javadoc>org.zkoss.zul.Tree</javadoc>) is assigned with a model, a default renderer is assigned too<ref>For the concept about component, model and renderer, please refer to [[ZK_Developer's_Reference/MVC/Model/List_Model#Model-driven_Display|the Model-driven Display section]].</ref>. The default renderer will assume that each tree item has only one column, and it converts the data into a string directly<ref>If the tree is assigned a template called <code>model</code>, then the template will be used to render the tree. For more information, please refer to [[ZK Developer's Reference/MVC/View/Template/Tree Template|the Tree Template section]].</ref>. If you want to display multiple columns or retrieve a particular field of the data, you have to implement <javadoc type="interface">org.zkoss.zul.TreeitemRenderer</javadoc> to handle the rendering.
  
 
For example,
 
For example,
Line 30: Line 30:
  
 
=Version History=
 
=Version History=
{{LastUpdated}}
+
 
 
{| class='wikitable' | width="100%"
 
{| class='wikitable' | width="100%"
 
! Version !! Date !! Content
 
! Version !! Date !! Content

Latest revision as of 07:34, 8 July 2022

When a tree (Tree) is assigned with a model, a default renderer is assigned too[1]. The default renderer will assume that each tree item has only one column, and it converts the data into a string directly[2]. If you want to display multiple columns or retrieve a particular field of the data, you have to implement TreeitemRenderer to handle the rendering.

For example,

public class HostTreeRenderer implements TreeitemRenderer {
	public void render(Treeitem treeitem, Object data, int index) throws Exception {
		Treerow row = treeitem.getTreerow();
		if (row == null) { // tree row not create yet.
			row = new Treerow();
			treeitem.appendChild(row);
		}
		if (data instanceof HostTreeModel.FakeGroup) {
			treeitem.getTreerow().appendChild(new Treecell(((HostTreeModel.FakeGroup)data).getName()));
		} else if (data instanceof HostTreeModel.FakeHost) {
			treeitem.getTreerow().appendChild(new Treecell(((HostTreeModel.FakeHost)data).getName()));
		} else if (data instanceof HostTreeModel.FakeProcess) {
			treeitem.getTreerow().appendChild(new Treecell(((HostTreeModel.FakeProcess)data).getName()));
		}
	}
}

  1. For the concept about component, model and renderer, please refer to the Model-driven Display section.
  2. If the tree is assigned a template called model, then the template will be used to render the tree. For more information, please refer to the Tree Template section.

Version History

Version Date Content
6.0.0 February 2012 The index argument was introduced.



Last Update : 2022/07/08

Copyright © Potix Corporation. This article is licensed under GNU Free Documentation License.