Difference between revisions of "Template:ItemRenderer"

From Documentation
(Created page with " Implementing your own (<javadoc type="interface">org.zkoss.zul.ItemRenderer</javadoc>) can customize how a component renders data in a browser. (For the concepts about compon...")
 
Line 3: Line 3:
  
 
'''Render an item with a tooltip'''
 
'''Render an item with a tooltip'''
<source lang="java">
+
<syntaxhighlight lang="java">
 
public class TooltipRenderer implements ItemRenderer {
 
public class TooltipRenderer implements ItemRenderer {
 
     @Override
 
     @Override
Line 10: Line 10:
 
     }
 
     }
 
}
 
}
 +
</syntaxhighlight>

Revision as of 03:26, 6 April 2023

Implementing your own (ItemRenderer) can customize how a component renders data in a browser. (For the concepts about component, model, and renderer, please refer to the Model-driven Display section). Notice that ItemRenderer should return an HTML snippet that is different from ListitemRenderer that creates components.

Render an item with a tooltip

public class TooltipRenderer implements ItemRenderer {
    @Override
    public String render(Component owner, Object data, int index) throws Exception {
        return String.format("<span title=\"%s\" style=\"width: 100%%;display: inline-block;\">%s</span>", data, data);
    }
}