Paging"

From Documentation
Line 26: Line 26:
 
[[Image:paging_mold_default.png ]]  
 
[[Image:paging_mold_default.png ]]  
  
When a user clicks on the hyperlinks, the <tt>onPaging</tt> event is sent with an instance of <javadoc>org.zkoss.zul.event.PagingEvent</javadoc> to the paging component. To decide which portion of your 100 items are visible, you shall add a listener to the paging component.
+
When a user clicks on the hyperlinks, the <tt>onPaging</tt> event is sent with an instance of <javadoc>org.zkoss.zul.event.PagingEvent</javadoc> to the paging component. To decide which portion of your 100 items are visible, you shall add a listener to the paging component. Please note that the code below is pseudo code, you can find a real world example [[Small_Talks/2008/June/Use_Load-On-Demand_to_Handle_Huge_Data|here]].
 +
 
 
<source lang="xml" >
 
<source lang="xml" >
 
<zk>
 
<zk>
 +
<div id="content"/> <!-- the long content is displayed here -->
 
<paging id="paging" />
 
<paging id="paging" />
 
 
Line 42: Line 44:
 
 
 
 
new Viewer().redraw(result, ofs, ofs + event.getPaginal().
+
new Viewer().redraw(content,
getPageSize() - 1);
+
result, ofs, ofs + event.getPaginal().getPageSize() - 1);
//assume redraw(List result, int b, int e) will display
+
//assume redraw(Div content, List result, int b, int e) will display
//from the b-th item to the e-th item
+
//the result to the content component from the b-th item to the e-th item
 
}
 
}
 
}
 
}

Revision as of 03:34, 21 December 2010

Paging

Employment/Purpose

A paging component is used with another component to separate long content into multiple pages. If a component has long content to display, you could separate them into pages, and then use a paging component as a controller to allow the user decide which page to display.

The listbox, grid and tree components support the paging intrinsically, so you don't need to specify a paging component explicitly. In other words, they will instantiate and manage a paging component automatically if the paging mold is specified. Of course, you could specify an external paging component, if you want to have different visual layout, or to control multiple listboxes, grids and/or trees with one single paging component.

Example

For example, suppose you have 100 items and prefer to show 20 items at a time, then you can use the paging components as follows.

 <vbox>
     <paging totalSize="100" pageSize="20"/>
 </vbox>

Paging mold default.png

When a user clicks on the hyperlinks, the onPaging event is sent with an instance of PagingEvent to the paging component. To decide which portion of your 100 items are visible, you shall add a listener to the paging component. Please note that the code below is pseudo code, you can find a real world example here.

<zk>
	<div id="content"/> <!-- the long content is displayed here -->
	<paging id="paging" />
	
	<zscript>
	List result = new SearchEngine().find("ZK");
	//assume SearchEngine.find() will return a list of items.
	
	paging.setTotalSize(result.size());
	paging.addEventListener("onPaging", new org.zkoss.zk.ui.event.EventListener() {
		public void onEvent(Event event) {
			int pgno = event.getPaginal().getActivePage();
			int ofs = pgno * event.getPaginal().getPageSize();
			
			
			new Viewer().redraw(content,
				result, ofs, ofs + event.getPaginal().getPageSize() - 1);
			//assume redraw(Div content, List result, int b, int e) will display
			//the result to the content component from the b-th item to the e-th item
			}
		}
	);
	</zscript>
</zk>

Supported Events

Name
Event Type
onPaging
Event: PagingEvent

Notifies one of the pages of a multi-page component is selected by the user.

Supported Molds

Available molds of a component are defined in lang.xml embedded in zul.jar.

Name
Snapshot
default
Paging mold default.png
os
Paging mold os.png

Supported Children

*NONE

Use Cases

Version Description Example Location
3.6 Smalltalk: Paging Sorting with a filter object Paging Sorting with a filter object
3.6 Live Data http://docs.zkoss.org/wiki/Live_Data,_Paging,_setModel_and_Implement_your_own_renderer

Version History

Last Update : 2010/12/21


Version Date Content
     



Last Update : 2010/12/21

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