|
Processing... Drag the scollbar down to dynamically load 250,000 items on demand!
Description & Source Code
This example demonstrates how data is not loaded until the requested data is needed in view, when scrolling down. load_on_demand.zul
<div apply="org.zkoss.bind.BindComposer" viewModel="@id('vm') @init('demo.listbox.load_on_demand.LoadOnDemandViewModel')"> <listbox id="list" model="@bind(vm.hugeList)" width="200px" height="540px"> <listhead> <listheader label="Load On Demand" sort="auto" /> </listhead> </listbox> <style> div.z-listbox-body .z-listcell { padding: 2px 5px; } </style> </div> LoadOnDemandViewModel.java
package demo.listbox.load_on_demand; import org.zkoss.zul.ListModel; public class LoadOnDemandViewModel { private ListModel<String> hugeList = new demo.listbox.load_on_demand.FakeListModel(250000); public ListModel<String> getHugeList() { return hugeList; } } FakeListModel.java
package demo.listbox.load_on_demand; import java.util.Comparator; import org.zkoss.zul.AbstractListModel; import org.zkoss.zul.event.ListDataEvent; import org.zkoss.zul.ext.Sortable; public class FakeListModel extends AbstractListModel<String> implements Sortable<String> { private static final long serialVersionUID = -3086046175152725037L; private int _size; private boolean _asc = true; public FakeListModel() { this(10000); } public FakeListModel(int size) { _size = size; } // ListModelExt // @Override public void sort(Comparator<String> cmpr, boolean asc) { _asc = asc; invalidate(); } public void invalidate() { fireEvent(ListDataEvent.CONTENTS_CHANGED, -1, -1); } // AbstractListModel // public String getElementAt(int v) { String value = "item"+(_asc ? v: _size - v); return value; } public int getSize() { return _size; } public void setSize(int size){ _size = size; } @Override public String getSortDirection(Comparator<String> arg0) { return null; } }
Copyright © 2005-2024 Potix Corporation All rights reserved.
|
Processing... |