Suggested case list:
Using timer to refresh a grid
383guest172.69.33.12125nk0uiMay 7, 2020 7:23:47 AMlinkuser model to move item to another listbox
120guest162.158.193.148d0n3krApr 2, 2020 5:28:28 AMlinkDisabled list item row passed to VM-1981
296fatih123160.83.36.13025nk0uiFeb 13, 2018 4:25:44 PMlinkDisabled list item row passed to VM-1981
295fatih123160.83.36.13025nk0uiFeb 13, 2018 4:25:16 PMlinkDisabled list item row passed to VM-1981
294fatih123160.83.36.13225nk0uiFeb 13, 2018 3:30:44 PMlinkgrid sample with ListModel/RowRenderer
816guest80.82.2.1312vah9ajFeb 21, 2017 11:42:21 AMlinkgrid sample with ListModel/RowRenderer
809guest175.98.113.1622vah9ajJan 26, 2017 9:19:33 AMlinkgrid sample with ListModel/RowRenderer
196guest79.185.142.402vah9ajApr 26, 2014 10:53:57 PMlinkgrid sample with ListModel/RowRenderer
195guest79.185.142.402vah9ajApr 26, 2014 10:53:54 PMlinkgrid sample with ListModel/RowRenderer
194guest79.185.142.402vah9ajApr 26, 2014 10:53:51 PMlinkgrid sample with ListModel/RowRenderer
193guest79.185.142.402vah9ajApr 26, 2014 10:53:48 PMlinkgrid sample with ListModel/RowRenderer
192guest79.185.142.402vah9ajApr 26, 2014 10:53:44 PMlinkgrid sample with ListModel/RowRenderer
191guest79.185.142.402vah9ajApr 26, 2014 10:53:40 PMlinkHierarchy table without using ZK PE/EE
1aaknai151.28.135.2131s871daJul 29, 2013 11:02:46 PMlinkgrid sample with ListModel/RowRenderer
128aaknai151.28.135.2132vah9ajJul 29, 2013 7:20:00 PMlinkuser model to move item to another listbox
1TonyQ114.25.109.94d0n3krApr 21, 2012 10:43:27 AMlinkUsing timer to refresh a grid
1TonyQ220.133.44.3725nk0uiFeb 17, 2012 3:17:34 AMlinkFire a event from child iframe
1TonyQ220.133.44.372eupjotFeb 3, 2012 5:04:52 AMlinkTextbox input restriction sample
1TonyQ72.21.245.2431b3nlr0Dec 20, 2011 10:09:10 AMlinkTest web core taglib in ZUL
1TonyQ198.203.175.175ofqkemDec 17, 2011 3:36:08 AMlinkLatest 10 Fiddles :
insert after component
15guest172.68.106.1691mum59Sep 6, 2024 7:44:46 AMlinkinsert after component
14guest172.68.106.1431mum59Sep 6, 2024 7:10:37 AMlinkAnother new ZK fiddle
5guest172.68.106.1843aipc9bSep 6, 2024 7:09:34 AMlinkUpdate listmodel doesn't affect Paging status
1guest172.70.207.2011hlltmhSep 6, 2024 6:37:41 AMlinkAnother new ZK fiddle
4guest172.68.106.1693aipc9bSep 6, 2024 6:35:00 AMlinkAnother new ZK fiddle
3guest172.68.106.1683aipc9bSep 6, 2024 6:34:19 AMlinkAnother new ZK fiddle
2guest172.68.106.1493aipc9bSep 6, 2024 6:32:46 AMlinkAnother new ZK fiddle
1guest172.68.106.1433aipc9bSep 6, 2024 6:27:54 AMlinkinsert after component
13guest172.68.106.1841mum59Sep 6, 2024 6:22:16 AMlinkinsert after component
12guest172.68.106.1431mum59Sep 6, 2024 6:19:22 AMlinkgrouped-list
5guest141.101.68.9837afusnJun 9, 2024 2:57:08 PMlinkresources
index.zulzul<zk>
<window apply="pkg$.TestComposer" vflex="1">
<grid id="grid" vflex="1" span="true">
<custom-attributes org.zkoss.zul.grid.rod="true"/>
<custom-attributes org.zkoss.zul.grid.preloadSize="100" />
<custom-attributes org.zkoss.zul.grid.initRodSize="50" />
<custom-attributes org.zkoss.zul.grid.autoSort="ignore.change"/>
<columns>
<column hflex="min" label="A" id="col1" sortDirection="ascending" iconSclass="z-icon-group" />
<column hflex="min" label="B" id="col2"/>
<column hflex="min" label="C" id="col3" align="right" />
<column hflex="min" label="Group" id="col4"/>
</columns>
<foot>
<footer />
<footer id="foot2" />
<footer id="foot3" />
</foot>
<auxhead>
<auxheader colspan="3">
<label id="counter" />
</auxheader>
<auxheader colspan="1">
<toolbarbutton label="Gruppieren nach"/>
</auxheader>
</auxhead>
<!--auxhead>
<auxheader colspan="3">
<groupbox>
<caption label="group action"/>
<button label="Click me" iconSclass="z-icon-check"/>
</groupbox>
</auxheader>
</auxhead-->
</grid>
</window>
</zk>
TestComposer.javajavaimport org.zkoss.zk.ui.*;
import org.zkoss.zk.ui.event.*;
import org.zkoss.zk.ui.util.*;
import org.zkoss.zk.ui.ext.*;
import org.zkoss.zk.au.*;
import org.zkoss.zk.au.out.*;
import org.zkoss.zul.*;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import pkg$.*;
public class TestComposer extends GenericForwardComposer{
private static final long serialVersionUID = 3120643218344891700L;
private final static int NUMBER_OF_GROUPS = 2000;
private final static int APPROXIMATE_MIN_GROUP_SIZE = 3000;
private final static int APPROXIMATE_MAX_GROUP_SIZE = 5000;
private Grid grid;
private Column col1;
private Column col2;
private Footer foot2;
private Footer foot3;
private Label counter;
private List<MyItem> itemList;
public void doAfterCompose(Component comp) throws Exception {
super.doAfterCompose(comp);
col1.setSortAscending(new ColumnOneComparator());
col1.setSortDescending(new ColumnOneComparator().reversed());
col2.setSortAscending(new ColumnTwoComparator());
col2.setSortDescending(new ColumnTwoComparator().reversed());
final MyRowRenderer renderer = new MyRowRenderer();
renderer.registerGroupToggle(this);
grid.setRowRenderer(renderer);
ListModelList<MyItem> model = new ListModelList<>();
grid.setModel(model);
// loading asynchronously
model.addAll(getData());
int sum = 0;
for (MyItem item: itemList) {
if (item.isGroup()) {
sum += item.getSum();
}
}
foot2.appendChild(new Label("Summe: "));
foot2.setAlign("right");
foot3.appendChild(new Label(String.valueOf(sum)));
counter.setValue("Einträge: " + itemList.size());
}
private List<MyItem> getData() {
List<MyItem> groups = new ArrayList<>(NUMBER_OF_GROUPS);
for (int i = 0; i < NUMBER_OF_GROUPS; i++) {
groups.add(new MyItem("group " + i));
}
ArrayList<MyItem> list = new ArrayList<>(groups);
itemList = new ArrayList<>();
int limit = NUMBER_OF_GROUPS * APPROXIMATE_MAX_GROUP_SIZE;
int offset = randomInt(APPROXIMATE_MIN_GROUP_SIZE, APPROXIMATE_MAX_GROUP_SIZE);
int group = 0;
for (int i = 0; i < limit; i++) {
list.add(new MyItem(groups.get(group), "a" + (limit - i), new String(new char[(int) (Math.random() * 5)]).replace("\0", "b") + i, i));
if (i > offset) {
if (++group >= NUMBER_OF_GROUPS) {
group--;
offset = limit;
} else {
offset += randomInt(APPROXIMATE_MIN_GROUP_SIZE, APPROXIMATE_MAX_GROUP_SIZE);
}
}
}
this.itemList = new ArrayList<>(list);
return list;
}
private int randomInt(int min, int max) {
int result = -1;
while(result < min) {
result = (int) (Math.random() * max);
}
return result;
}
public void toggleGroup(MyItem item) {
item.setCollapsed(!item.isCollapsed());
updateModel();
}
private void updateModel() {
List<MyItem> newList = new ArrayList<>(itemList);
newList.removeIf(item -> !item.isGroup() && item.getGroup().isCollapsed());
grid.setModel(new ListModelList<>(newList));
}
}
MyItem.javajavaimport org.zkoss.zk.ui.*;
import org.zkoss.zk.ui.event.*;
import org.zkoss.zk.ui.util.*;
import org.zkoss.zk.ui.ext.*;
import org.zkoss.zk.au.*;
import org.zkoss.zk.au.out.*;
import org.zkoss.zul.*;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import pkg$.*;
public class MyItem extends GenericForwardComposer {
public MyItem group;
public boolean collapsed;
public String v1;
public String v2;
public int v3;
private List<MyItem> children = new ArrayList<>();
public MyItem(MyItem group, String v1, String v2, int v3) {
this(v1, v2, v3);
this.group = group;
group.register(this);
}
public MyItem(String v1) {
this(v1, null, 0);
}
public MyItem(String v1, String v2, int v3) {
this.v1 = v1;
this.v2 = v2;
this.v3 = v3;
}
boolean isGroup() {
return group == null;
}
void register(MyItem item) {
children.add(item);
}
public int getSum() {
if (!isGroup()) {
return -1;
}
int result = 0;
for (MyItem item : children) {
result += item.v3;
}
return result;
}
public void setCollapsed(boolean collapsed) {
this.collapsed = collapsed;
}
public boolean isCollapsed() {
return collapsed;
}
public int compareTo(MyItem o) {
return new ColumnOneComparator().compare(this, o);
}
public MyItem getGroup() {
return group;
}
}
MyRowRenderer.javajavaimport org.zkoss.zk.ui.*;
import org.zkoss.zk.ui.event.*;
import org.zkoss.zk.ui.util.*;
import org.zkoss.zk.ui.ext.*;
import org.zkoss.zk.au.*;
import org.zkoss.zk.au.out.*;
import org.zkoss.zul.*;
import org.zkoss.zhtml.I;
public class MyRowRenderer implements RowRenderer<Object> {
private TestComposer composer;
public void render(final Row row, final Object data, int index) {
final MyItem item = (MyItem) data;
if (item.isGroup()) {
row.setStyle("background:#6f6f6f;color:#fff;font-weight:bold;cursor:pointer");
Cell cell1 = createCell(row, new Label(" " + item.v1));
createCell(row, new Label(""));
I icon = new I();
cell1.insertBefore(icon, cell1.getFirstChild());
if (item.isCollapsed()) {
icon.setSclass("z-icon-chevron-down");
} else {
icon.setSclass("z-icon-chevron-up");
}
createCell(row, new Label(String.valueOf(item.getSum())));
createCell(row, new Label(""));
row.addEventListener(Events.ON_CLICK, evt -> composer.toggleGroup(item));
} else {
createCell(row, new Label(item.v1));
createCell(row, new Label(item.v2));
createCell(row, new Label(String.valueOf(item.v3)));
createCell(row, new Label(item.group.v1));
}
}
void registerGroupToggle(TestComposer composer) {
this.composer = composer;
}
private Cell createCell(Row row, Label label) {
return createCell(row, label, null);
}
private Cell createCell(Row row, Label label, String style) {
Cell cell = new Cell();
cell.setParent(row);
cell.appendChild(label);
if (style != null) {
cell.setStyle(style);
}
return cell;
}
}
ColumnComparator.javajavaimport org.zkoss.zk.ui.*;
import org.zkoss.zk.ui.event.*;
import org.zkoss.zk.ui.util.*;
import org.zkoss.zk.ui.ext.*;
import org.zkoss.zk.au.*;
import org.zkoss.zk.au.out.*;
import org.zkoss.zul.*;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import pkg$.*;
public class ColumnComparator extends GenericForwardComposer implements Comparator<MyItem> {
private final boolean reversed;
private final Comparator<MyItem> itemComparator;
public ColumnComparator(Comparator<MyItem> itemComparator) {
this(itemComparator, false);
}
private ColumnComparator(Comparator<MyItem> itemComparator, boolean reversed) {
this.reversed = reversed;
this.itemComparator = itemComparator;
}
public int compare(MyItem o1, MyItem o2) {
return compareWithGroups(o1, o2);
}
public final Comparator<MyItem> reversed() {
return new ColumnComparator(itemComparator, true);
}
private int compareWithGroups(MyItem o1, MyItem o2) {
if (o1 == o2) {
return 0;
}
if (o1.isGroup()) {
if (o2.isGroup()) {
return (reversed ? -1 : 1) * o1.v1.compareTo(o2.v1);
} else if (o2.group == o1) {
return -1;
}
return (reversed ? -1 : 1) * o1.v1.compareTo(o2.group.v1);
}
if (o2.isGroup()) {
if (o1.group == o2) {
return 1;
}
return (reversed ? -1 : 1) * o1.group.v1.compareTo(o2.v1);
}
if (o1.group != o2.group) {
return (reversed ? -1 : 1) * o1.group.v1.compareTo(o2.group.v1);
}
return (reversed ? -1 : 1) * itemComparator.compare(o1, o2);
}
}
ColumnOneComparator.javajavaimport org.zkoss.zk.ui.*;
import org.zkoss.zk.ui.event.*;
import org.zkoss.zk.ui.util.*;
import org.zkoss.zk.ui.ext.*;
import org.zkoss.zk.au.*;
import org.zkoss.zk.au.out.*;
import org.zkoss.zul.*;
import java.util.Comparator;
import pkg$.*;
public class ColumnOneComparator extends ColumnComparator {
public ColumnOneComparator() {
super(Comparator.comparing(o -> o.v1));
}
}
ColumnTwoComparator.javajavaimport org.zkoss.zk.ui.*;
import org.zkoss.zk.ui.event.*;
import org.zkoss.zk.ui.util.*;
import org.zkoss.zk.ui.ext.*;
import org.zkoss.zk.au.*;
import org.zkoss.zk.au.out.*;
import org.zkoss.zul.*;
import java.util.Comparator;
import pkg$.*;
public class ColumnTwoComparator extends ColumnComparator {
public ColumnTwoComparator() {
super(Comparator.comparing(o -> o.v2));
}
}