Grids with Paging

There are two ways to handle long content in a grid: scrolling and paging. The scrolling is enabled by specifying the height property as discussed in the previous section. The paging is enabled by specifying paging to the mold property. Once paging is enable, the grid separates the content into several pages and displays one page at a time as depicted below.

<grid width="300px" mold="paging" pageSize="4">
    <columns>    
        <column label="Left"/>        
        <column label="Right"/>        
    </columns>    
    <rows>    
        <row>        
            <label value="Item 1.1"/><label value="Item 1.2"/>            
        </row>        
        <row>        
            <label value="Item 2.1"/><label value="Item 2.2"/>            
        </row>        
        <row>        
            <label value="Item 3.1"/><label value="Item 3.2"/>            
        </row>        
        <row>        
            <label value="Item 4.1"/><label value="Item 4.2"/>            
        </row>        
        <row>        
            <label value="Item 5.1"/><label value="Item 5.2"/>            
        </row>        
        <row>        
            <label value="Item 6.1"/><label value="Item 6.2"/>            
        </row>        
        <row>        
            <label value="Item 7.1"/><label value="Item 7.2"/>            
        </row>        
    </rows>    
</grid>

Once the paging mold is set, the grid creates an instance of the paging component as the child of the grid. It then takes care of paging for the grid it belongs to.

The pageSize Property

Once setting the paging mold, you can specify how many rows are visible at a time (i.e., the page size) by use of the pageSize property. By default, it is 20.

The paginal Property

If you prefer to put the paging component at different location or you want to control two or more grid with the same paging component, you can assign the paginal property explicitly. Note: if it is not set explicitly, it is the same as the paging property.

<vbox>
<paging id="pg" pageSize="4"/>
<hbox>
    <grid width="300px" mold="paging" paginal="${pg}">    
        <columns>        
            <column label="Left"/><column label="Right"/>            
        </columns>        
        <rows>        
            <row>            
                <label value="Item 1.1"/><label value="Item 1.2"/>                
            </row>            
            <row>            
                <label value="Item 2.1"/><label value="Item 2.2"/>                
            </row>            
            <row>            
                <label value="Item 3.1"/><label value="Item 3.2"/>                
            </row>            
            <row>            
                <label value="Item 4.1"/><label value="Item 4.2"/>                
            </row>            
            <row>            
                <label value="Item 5.1"/><label value="Item 5.2"/>                
            </row>            
            <row>            
                <label value="Item 6.1"/><label value="Item 6.2"/>                
            </row>            
            <row>            
                <label value="Item 7.1"/><label value="Item 7.2"/>                
            </row>            
        </rows>        
    </grid>    
    <grid width="300px" mold="paging" paginal="${pg}">    
        <columns>        
            <column label="Left"/><column label="Right"/>            
        </columns>        
        <rows>        
            <row>            
                <label value="Item A.1"/><label value="Item A.2"/>                
            </row>            
            <row>            
                <label value="Item B.1"/><label value="Item B.2"/>                
            </row>            
            <row>            
                <label value="Item C.1"/><label value="Item C.2"/>                
            </row>            
            <row>            
                <label value="Item D.1"/><label value="Item D.2"/>                
            </row>            
            <row>            
                <label value="Item E.1"/><label value="Item E.2"/>                
            </row>            
            <row>            
                <label value="Item F.1"/><label value="Item F.2"/>                
            </row>            
        </rows>        
    </grid>    
</hbox>
</vbox>

The paging Property

It is a readonly property representing the child paging component that is created automatically to handling paging. It is null if you assign an external paging by the paginal property. You rarely need to access this property. Rather, use the paginal property.

The onPaging Event and Method

Once a user clicks the page number of the paging component, an onPaging event is sent the grid. It is then processed by the onPaging method. By default, the method invalidates, i.e., redraws, the content of rows.

If you want to implement "create-on-demand" feature, you can add a event listener to the grid for the onPaging event.

grid.addEventListener(org.zkoss.zul.event.ZulEvents.ON_PAGING, new MyListener());