Learn About How Grouping Works with Live Data

Jumper Chen, Engineer, Potix Corporation
May 6, 2008

Version

Applicable to zk-3.1.0-FL-2008-05-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 GroupModel, a interface to be used with ListModel to represent a list model with grouping.

Live Demo

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

The following code is a Listbox example,

  ...
<zk>
  <zscript>
    String[] data = new String[50];
    for(int j=0; j &lt; data.length; ++j) {
      data[j] = "option "+j;
    }
    ListModel strset = new SimpleGroupModel(data, new int[]{13, 3, 14, 16});
  </zscript>
  <listbox width="200px" rows="20" model="&#36;{strset}">
    <listhead>
      <listheader label="Load on Demend (Listbox)" sort="auto"/>
    </listhead>
  </listbox>
</zk>
  ...

As you can see, the demo code is similar to using ListModel without grouing from our demo site, and the SimpleGroupModel provides a extra parameter, an int array to indicate the number of items belong to the indexed group. For the above example, the int array means it has 4 groups and each group has 13, 3, 14, and 16 items (exclusive).

Note: If you wanna know more details, please refer to the SimpleGroupModel 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
5 days ago

hhh

 
 
Leave a Reply
 
Name (required)
Mail (will not be published)(required)
Website
(Case Insensitive)
Bold text Italic text UnderLine text Source Code Horizontal ruler External Link
SourceForge.net