Learn About How Grouping Works with Live Data

Jumper Chen, Engineer, Potix Corporation
May 6, 2008

Version

Applicable to zk-3.5.0-FL-2008-09-05 and later.

Introduction

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,

<zk>
	<zscript>
	...
	<![CDATA[  
		/** 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);
	]]>
	</zscript>
	<listbox width="300px" height="500px" model="${model}">
		<listhead>
			<listheader label="Live Data" sort="auto" />
		</listhead>
	</listbox>
</zk>

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

Download the liveDataGrouping.zip for the article here.

Summary

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.

Comments
 
martin
2008-05-06

hhh

tonychen
2008-10-14

It's useful, but the demo only has one column. So I want to know if there are two or more columns, how should I do?

thx!

Felipe Cypriano
2009-06-15

I'm asking myself the same thing as tonychen.

I'm trying to use ArrayGroupsModel with GroupComparator, but it always generates one column and I couldn't find an example of a renderer for this case.

Ondrej Medek
2009-08-13

@tonychen
What about to try to make a List as items in the 2nd dimension of the data?

 
 
Leave a Reply
 
Name (required)
Mail (will not be published) (required)
Website
(Case Insensitive)
Bold textItalic textUnderLine textSource CodeHorizontal rulerExternal Link
Post
Preview