Learn About How Grouping Works with Live Data

From Documentation
DocumentationSmall Talks2008MayLearn About How Grouping Works with Live Data
Learn About How Grouping Works with Live Data

Jumper Chen, Engineer, Potix Corporation
May 6, 2008
Applicable to zk-3.5.0-FL-2008-09-05 and later.


In the previous article (here), we have illustrated how to use the grouping feature. In this article, we'll talk about how to manipulate live data with grouping. Live data, a ListModel that separates the data from user interface, is a common sense of using Listbox and Grid in the majority developer who use ZK framework. Nonetheless, ListModel is insufficient for grouping needs, so we provide the GroupsModel, a interface to be used to provide grouping feature in both grid and listbox.

Live Demo

Here is a live data with grouping example. We use the SimpleGroupsModel, which implements the GroupsModel interface.

The following code is a Listbox example,

		/** get groups data, it is a 2 dimension array, objects in same array means same group**/
		String[][] data = getData();
		/** define head object of group **/
		String[] heads = new String[]{"Group A","Group B","Group C","Group D"};
		/** define foot object of group, a null object means no foot **/ 
		String[] foots = new String[]{"Foot A",null,"Foot C","Foot D"};
		GroupsModel model = new SimpleGroupsModel(data,heads,foots);
	<listbox width="300px" height="500px" model="${model}">
			<listheader label="Live Data" sort="auto" />

As you can see, you need to provide a two dimension object array as data for the group, objects in same array means in same group. You also need to provide two extra arrays to construct heads and foots. The array size(first dimension) of data must equals to the size of heads and foots. If you don't want to has foot for some group, then just set null to object in the foots array.

Note: If you wanna know more details, please refer to the SimpleGroupsModel API, and this demo code can be found in the liveDataGrouping.zip file.


Download the liveDataGrouping.zip for the article here.


ZK supports the grouping feature with live data, and it is useful for developer. If you come up with any problem, please feel free to ask us on ZK forum.

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