Learn About How Grouping Works with Live Data

From Documentation
Revision as of 03:19, 14 December 2010 by Char (talk | contribs) (→‎Introduction)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
DocumentationSmall Talks2008MayLearn About How Grouping Works with Live Data
Learn About How Grouping Works with Live Data

Author
Jumper Chen, Engineer, Potix Corporation
Date
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.




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