Grid Renderer"

From Documentation
m ((via JWB))
m ((via JWB))
 
(3 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
{{ZKDevelopersReferencePageHeader}}
 
{{ZKDevelopersReferencePageHeader}}
  
When a grid (<javadoc>org.zkoss.zul.Grid</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 row has only one column, and it converts the data into a string directly<ref>If the grid is assigned a template called <tt>model</tt>, then the template will be used to render the grid. For more information, please refer to [[ZK Developer's Reference/MVC/View/Template/Grid Template|the Grid 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.RowRenderer</javadoc> to handle the rendering.
+
When a <javadoc>org.zkoss.zul.Grid</javadoc> is assigned with a model, a default renderer is assigned too (see [[ZK_Developer's_Reference/MVC/Model/List_Model#Model-driven_Display|the Model-driven Display ]]). The default renderer will assume that each row has only one column, and it converts the data into a string directly<ref>If the grid is assigned a template called <code>model</code>, then the template will be used to render the grid. For more information, please refer to [[ZK Developer's Reference/MVC/View/Template/Grid Template|the Grid 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.RowRenderer</javadoc> to handle the rendering and assign it by [https://www.zkoss.org/javadoc/latest/zk/org/zkoss/zul/Grid.html#setRowRenderer-org.zkoss.zul.RowRenderer- setRowRenderer()].
  
 
For example,
 
For example,
Line 26: Line 26:
  
 
=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 Grid is assigned with a model, a default renderer is assigned too (see the Model-driven Display ). The default renderer will assume that each row has only one column, and it converts the data into a string directly[1]. If you want to display multiple columns or retrieve a particular field of the data, you have to implement RowRenderer to handle the rendering and assign it by setRowRenderer().

For example,

public class FoodGroupRenderer implements RowRenderer, java.io.Serializable {
    public void render(Row row, Object obj, int index) {
        if (row instanceof Group) {
            row.appendChild(new Label(obj.toString()));
        } else {
            User user = (User) obj;
            row.appendChild(new Label(user.getName()));
            row.appendChild(new Label(user.getDescription()));
            row.appendChild(new Label(user.getDomain()));
        }
    }
}

  1. If the grid is assigned a template called model, then the template will be used to render the grid. For more information, please refer to the Grid 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.