Difference between revisions of "Template:ItemRenderer"
From Documentation
Line 2: | Line 2: | ||
For those components that have no child components e.g. [[ZK%20Component%20Reference/Input/Chosenbox| Chosenbox]], [[ZK%20Component%20Reference/Essential%20Components/Selectbox| Selectbox]], [[ZK%20Component%20Reference/Input/Cascader| Cascader]], [[ZK%20Component%20Reference/Input/Searchbox| Searchbox]], their built-in renderers will directly wrap your data into an HTML snippet. Remember to escape HTML characters on your own. | For those components that have no child components e.g. [[ZK%20Component%20Reference/Input/Chosenbox| Chosenbox]], [[ZK%20Component%20Reference/Essential%20Components/Selectbox| Selectbox]], [[ZK%20Component%20Reference/Input/Cascader| Cascader]], [[ZK%20Component%20Reference/Input/Searchbox| Searchbox]], their built-in renderers will directly wrap your data into an HTML snippet. Remember to escape HTML characters on your own. | ||
− | 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 component, model, and renderer, please refer to [[ZK_Developer's_Reference/MVC/Model/List_Model#Model-driven_Display|the Model-driven Display section]]). Notice that <code>ItemRenderer</code> should return an HTML snippet that is different from <javadoc type="interface">org.zkoss.zul.ListitemRenderer</javadoc> that creates components. | + | Implementing your own (<javadoc type="interface">org.zkoss.zul.ItemRenderer</javadoc>) can customize how a component renders data in a browser without javascript. (For the concepts about component, model, and renderer, please refer to [[ZK_Developer's_Reference/MVC/Model/List_Model#Model-driven_Display|the Model-driven Display section]]). Notice that <code>ItemRenderer</code> should return an HTML snippet that is different from <javadoc type="interface">org.zkoss.zul.ListitemRenderer</javadoc> that creates components. |
'''Render an item with a tooltip''' | '''Render an item with a tooltip''' |
Revision as of 04:58, 8 May 2023
For those components that have no child components e.g. Chosenbox, Selectbox, Cascader, Searchbox, their built-in renderers will directly wrap your data into an HTML snippet. Remember to escape HTML characters on your own.
Implementing your own (ItemRenderer) can customize how a component renders data in a browser without javascript. (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);
}
}