| org.zkoss.zul.impl.XulElement org.zkoss.zul.Grid
Grid | public class Grid extends XulElement (Code) | | A grid is an element that contains both rows and columns elements.
It is used to create a grid of elements.
Both the rows and columns are displayed at once although only one will
typically contain content, while the other may provide size information.
Besides creating
Row programmingly, you can assign
a data model (a
ListModel instance) to a grid via
Grid.setModel and then the grid will retrieve data
by calling
ListModel.getElementAt when necessary.
Besides assign a list model, you could assign a renderer
(a
RowRenderer instance) to a grid, such that
the grid will use this
renderer to render the data returned by
ListModel.getElementAt .
If not assigned, the default renderer, which assumes a label per row,
is used.
In other words, the default renderer adds a label to
a row by calling toString against the object returned
by
ListModel.getElementAt There are two ways to handle long content: scrolling and paging.
If
Grid.getMold is "default", scrolling is used if
Grid.setHeight is called and too much content to display.
If
Grid.getMold is "paging", paging is used if two or more pages are
required. To control the number of rows to display in a page, use
Grid.setPageSize .
If paging is used, the page controller is either created automatically
or assigned explicity by
Grid.setPaginal .
The paging controller specified explicitly by
Grid.setPaginal is called
the external page controller. It is useful if you want to put the paging
controller at different location (other than as a child component), or
you want to use the same controller to control multiple grids.
Default
Grid.getSclass : grid.
To have a grid without stripping, you can specify a non-existent
style class to
Grid.setOddRowSclass .
If you want to disable all striping, you can specify the style:
tr.odd td.gc {
background: white;
}
author: tomyeh See Also: ListModel See Also: RowRenderer See Also: RowRendererExt |
Constructor Summary | |
public | Grid() |
Method Summary | |
public Object | clone() | public String | getAlign() Returns the horizontal alignment of the whole grid. | public Component | getCell(int row, int col) Returns the specified cell, or null if not available. | public Columns | getColumns() Returns the columns. | public Foot | getFoot() Returns the foot. | public Collection | getHeads() Returns a collection of heads, including
Grid.getColumns and auxiliary heads (
Auxhead ) (never null). | public String | getInnerWidth() Returns the inner width of this component. | public ListModel | getModel() Returns the list model associated with this grid, or null
if this grid is not associated with any list data model. | public String | getOddRowSclass() Returns the style class for the odd rows. | public String | getOuterAttrs() | public int | getPageSize() Returns the page size, aka., the number rows per page. | public Paginal | getPaginal() Returns the paging controller, or null if not available. | public Paging | getPaging() Returns the child paging controller that is created automatically,
or null if mold is not "paging", or the controller is specified externally
by
Grid.setPaginal . | public int | getPreloadSize() Returns the number of rows to preload when receiving
the rendering request from the client. | public RowRenderer | getRowRenderer() Returns the renderer to render each row, or null if the default
renderer is used. | public Rows | getRows() Returns the rows. | boolean | inPagingMold() Returns whether this grid is in the paging mold. | public boolean | insertBefore(Component newChild, Component refChild) | protected Object | newExtraCtrl() | public void | onInitRender() Handles a private event, onInitRender. | public boolean | removeChild(Component child) | public void | renderAll() Renders all
Row if not loaded yet,
with
Grid.getRowRenderer . | public void | renderItems(Set rows) | public void | renderRow(Row row) Renders the specified
Row if not loaded yet,
with
Grid.getRowRenderer . | public void | renderRows(Set rows) Renders a set of specified rows. | public void | setAlign(String align) Sets the horizontal alignment of the whole grid. | public void | setInnerWidth(String innerWidth) Sets the inner width of this component.
The inner width is the width of the inner table.
By default, it is 100%. | public void | setModel(ListModel model) Sets the list model associated with this grid. | public void | setMold(String mold) | public void | setOddRowSclass(String scls) Sets the style class for the odd rows. | public void | setPageSize(int pgsz) Sets the page size, aka., the number rows per page. | public void | setPaginal(Paginal pgi) | public void | setPreloadSize(int sz) Sets the number of rows to preload when receiving
the rendering request from the client.
It is used only if live data (
Grid.setModel and
not paging (
Grid.getPaging .
Parameters: sz - the number of rows to preload. | public void | setRowRenderer(RowRenderer renderer) Sets the renderer which is used to render each row
if
Grid.getModel is not null. | public void | setRowRenderer(String clsnm) Sets the renderer by use of a class name. |
getAlign | public String getAlign()(Code) | | Returns the horizontal alignment of the whole grid.
Default: null (system default: left unless CSS specified).
|
getCell | public Component getCell(int row, int col)(Code) | | Returns the specified cell, or null if not available.
Parameters: row - which row to fetch (starting at 0). Parameters: col - which column to fetch (starting at 0). |
getFoot | public Foot getFoot()(Code) | | Returns the foot.
|
getInnerWidth | public String getInnerWidth()(Code) | | Returns the inner width of this component.
The inner width is the width of the inner table.
Default: "100%"
See Also: Grid.setInnerWidth since: 3.0.0 |
getModel | public ListModel getModel()(Code) | | Returns the list model associated with this grid, or null
if this grid is not associated with any list data model.
|
getOddRowSclass | public String getOddRowSclass()(Code) | | Returns the style class for the odd rows.
Default: odd.
since: 3.0.0 |
getPageSize | public int getPageSize()(Code) | | Returns the page size, aka., the number rows per page.
exception: IllegalStateException - if Grid.getPaginal returns null,i.e., mold is not "paging" and no external controller is specified. |
getPaginal | public Paginal getPaginal()(Code) | | Returns the paging controller, or null if not available.
Note: the paging controller is used only if
Grid.getMold is "paging".
If mold is "paging", this method never returns null, because
a child paging controller is created automcatically (if not specified
by developers with
Grid.setPaginal ).
If a paging controller is specified (either by
Grid.setPaginal ,
or by
Grid.setMold with "paging"),
the grid will rely on the paging controller to handle long-content
instead of scrolling.
|
getPaging | public Paging getPaging()(Code) | | Returns the child paging controller that is created automatically,
or null if mold is not "paging", or the controller is specified externally
by
Grid.setPaginal .
|
getPreloadSize | public int getPreloadSize()(Code) | | Returns the number of rows to preload when receiving
the rendering request from the client.
Default: 7.
It is used only if live data (
Grid.setModel and
not paging (
Grid.getPaging .
since: 2.4.1 |
getRowRenderer | public RowRenderer getRowRenderer()(Code) | | Returns the renderer to render each row, or null if the default
renderer is used.
|
getRows | public Rows getRows()(Code) | | Returns the rows.
|
inPagingMold | boolean inPagingMold()(Code) | | Returns whether this grid is in the paging mold.
|
onInitRender | public void onInitRender()(Code) | | Handles a private event, onInitRender. It is used only for
implementation, and you rarely need to invoke it explicitly.
|
renderItems | public void renderItems(Set rows)(Code) | | |
renderRow | public void renderRow(Row row)(Code) | | Renders the specified
Row if not loaded yet,
with
Grid.getRowRenderer .
It does nothing if
Grid.getModel returns null.
In other words, it is meaningful only if live data model is used.
|
setAlign | public void setAlign(String align)(Code) | | Sets the horizontal alignment of the whole grid.
Allowed: "left", "center", "right"
|
setInnerWidth | public void setInnerWidth(String innerWidth)(Code) | | Sets the inner width of this component.
The inner width is the width of the inner table.
By default, it is 100%. That is, it is the same as the width
of this component. However, it is changed when the user
is sizing the column's width.
Application developers rarely call this method, unless
they want to preserve the widths of sizable columns
changed by the user.
To preserve the widths, the developer have to store the widths of
all columns and the inner width (
Grid.getInnerWidth ),
and then restore them when re-creating this component.
Parameters: innerWidth - the inner width. If null, "100%" is assumed. since: 3.0.0 |
setModel | public void setModel(ListModel model)(Code) | | Sets the list model associated with this grid.
If a non-null model is assigned, no matter whether it is the same as
the previous, it will always cause re-render.
Parameters: model - the list model to associate, or null to dis-associateany previous model. exception: UiException - if failed to initialize with the model |
setOddRowSclass | public void setOddRowSclass(String scls)(Code) | | Sets the style class for the odd rows.
If the style class doesn't exist, the striping effect disappears.
You can provide different effects by providing the proper style
classes.
since: 3.0.0 |
setPageSize | public void setPageSize(int pgsz)(Code) | | Sets the page size, aka., the number rows per page.
exception: IllegalStateException - if Grid.getPaginal returns null,i.e., mold is not "paging" and no external controller is specified. |
setPreloadSize | public void setPreloadSize(int sz)(Code) | | Sets the number of rows to preload when receiving
the rendering request from the client.
It is used only if live data (
Grid.setModel and
not paging (
Grid.getPaging .
Parameters: sz - the number of rows to preload. If zero, no preloadat all. exception: UiException - if sz is negative since: 2.4.1 |
setRowRenderer | public void setRowRenderer(RowRenderer renderer)(Code) | | Sets the renderer which is used to render each row
if
Grid.getModel is not null.
Note: changing a render will not cause the grid to re-render.
If you want it to re-render, you could assign the same model again
(i.e., setModel(getModel())), or fire an
ListDataEvent event.
Parameters: renderer - the renderer, or null to use the default. exception: UiException - if failed to initialize with the model |
|
|