|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.zkoss.zk.ui.AbstractComponent org.zkoss.zk.ui.HtmlBasedComponent org.zkoss.zul.impl.XulElement org.zkoss.zul.impl.MeshElement org.zkoss.zul.Grid
public class Grid
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.
Events: onAfterRender
onAfterRender is sent when the model's data has been rendered.(since 5.0.4)
Besides creating Row
programmatically, you can assign
a data model (a ListModel
or GroupsModel
instance) to a grid via
setModel(ListModel)
or setModel(GroupsModel)
and then the grid will retrieve data
by calling ListModel.getElementAt(int)
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(int)
.
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(int)
There are two ways to handle long content: scrolling and paging.
If AbstractComponent.getMold()
is "default", scrolling is used if HtmlBasedComponent.setHeight(java.lang.String)
is called and too much content to display.
If AbstractComponent.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
MeshElement.setPageSize(int)
.
If paging is used, the page controller is either created automatically
or assigned explicitly by setPaginal(org.zkoss.zul.ext.Paginal)
.
The paging controller specified explicitly by setPaginal(org.zkoss.zul.ext.Paginal)
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 getZclass()
: z-grid.(since 3.5.0)
To have a grid without stripping, you can specify a non-existent
style class to setOddRowSclass(java.lang.String)
.
When used in a clustering environment, you have to make RowRenderer
(setRowRenderer(org.zkoss.zul.RowRenderer>)
) and ListModel
(setModel(org.zkoss.zul.ListModel>)
) either
serializable or re-assign them when sessionDidActivate(org.zkoss.zk.ui.Page)
is called.
For huge data, you can turn on Grid's ROD to request ZK engine to load from
ListModel
only the required data chunk and create only the required
Row
s in memory and render only the required DOM elements in browser.
So it saves both the memory and the processing time in both server and browser
for huge data. If you don't use the ListModel
with the Grid, turn on
the ROD will still have ZK engine to render only a chunk of DOM elements in
browser so it at least saves the memory and processing time in browser. Note
that ROD works only if the Grid is configured to has a limited "view port"
height. That is, either the Grid is in the "paging" mold or you have to
HtmlBasedComponent.setHeight(String)
or HtmlBasedComponent.setVflex(String)
of the Grid to
make ROD works.
You can turn on/off ROD for all Grids in the application or only for a specific Grid. To turn on ROD for all Grids in the application, you have to specify the Library Property "org.zkoss.zul.grid.rod" to "true" in WEB-INF/zk.xml. If you did not specify the Library Property, default is false.
org.zkoss.zul.grid.rod
true
To turn on ROD for a specific Grid, you have to specify the Grid's attribute map with key "org.zkoss.zul.grid.rod" to true. That is, for example, if in a zul file, you shall specify <custom-attributes> of the Grid like this:
You can mix the Library Property and <custom-attributes> ways together. The <custom-attributes> way always takes higher priority. So you can turn OFF ROD in general and turn ON only some specific Grid component. Or you can turn ON ROD in general and turn OFF only some specific Grid component.
Since only partial Row
s are created and rendered in the Grid if
you turn the ROD on, there will be some limitations on accessing Row
s.
For example, if you call
Row rowAt100 = (Row) getRows().getChildren().get(100);
The Row
in index 100 is not necessary created yet if it is not in the
current "view port" and you will get "null" instead.
And it is generally a bad idea to "cache" the created Row
in your
application if you turn the ROD on because rows might be removed later.
Basically, you shall operate on the item of the ListModel rather than on the
Row
if you use the ListModel and ROD.
setModel(org.zkoss.zul.ListModel>)
is called and Column.setSortDirection(java.lang.String)
is set.Column.setSortDirection(java.lang.String)
is called.ListDataEvent
and Column.setSortDirection(java.lang.String)
is set.ListDataEvent
,
you can specifies the value as "ignore.change".
Notice that you could specify this attribute in any of its ancestor's attributes.
It will be inherited.It is used only if live data (setModel(ListModel)
and
not paging (getPagingChild()
).
It is used only if live data (setModel(ListModel)
and not paging
(getPagingChild()
).
ListModel
,
RowRenderer
,
RowRendererExt
,
Serialized FormNested Class Summary | |
---|---|
protected class |
Grid.ExtraCtrl
A utility class to implement HtmlBasedComponent.getExtraCtrl() . |
Nested classes/interfaces inherited from class org.zkoss.zul.impl.MeshElement |
---|
MeshElement.InternalPaging |
Nested classes/interfaces inherited from class org.zkoss.zk.ui.AbstractComponent |
---|
AbstractComponent.Children |
Field Summary |
---|
Fields inherited from class org.zkoss.zk.ui.HtmlBasedComponent |
---|
_zclass |
Fields inherited from interface org.zkoss.zk.ui.Component |
---|
APPLICATION_SCOPE, COMPONENT_SCOPE, DESKTOP_SCOPE, PAGE_SCOPE, REQUEST_SCOPE, SESSION_SCOPE, SPACE_SCOPE |
Fields inherited from interface org.zkoss.zk.ui.sys.ComponentCtrl |
---|
CE_BUSY_IGNORE, CE_DUPLICATE_IGNORE, CE_IMPORTANT, CE_NON_DEFERRABLE, CE_REPEAT_IGNORE |
Constructor Summary | |
---|---|
Grid()
|
Method Summary | ||
---|---|---|
void |
beforeChildAdded(Component newChild,
Component refChild)
Default: does nothing. |
|
java.lang.Object |
clone()
Clones the component. |
|
java.lang.String |
getAlign()
Deprecated. As of release 5.0, use CSS instead. |
|
Component |
getCell(int row,
int col)
Returns the specified cell, or null if not available. |
|
Columns |
getColumns()
Returns the columns. |
|
java.lang.String |
getEmptyMessage()
|
|
java.lang.Object |
getExtraCtrl()
Returns the client control for this component. |
|
Foot |
getFoot()
Returns the foot. |
|
Frozen |
getFrozen()
Returns the frozen child. |
|
|
getGroupsModel()
Returns the groups model associated with this grid, or null if this grid is associated with a ListModel
or not associated with any list data model. |
|
java.util.Collection<Component> |
getHeads()
Returns a collection of heads, including getColumns()
and auxiliary heads (Auxhead ) (never null). |
|
java.lang.String |
getInnerWidth()
Returns the inner width of this component. |
|
|
getListModel()
Returns the list model associated with this grid, or null if this grid is associated with a GroupsModel
or not associated with any list data model. |
|
|
getModel()
Returns the model associated with this grid, or null if this grid is not associated with any list data model. |
|
java.lang.String |
getOddRowSclass()
Returns the style class for the odd rows. |
|
Paginal |
getPaginal()
Returns the paging controller, or null if not available. |
|
Paging |
getPagingChild()
Returns the child paging controller that is created automatically, or null if mold is not "paging", or the controller is specified externally by setPaginal(org.zkoss.zul.ext.Paginal) . |
|
int |
getPreloadSize()
Deprecated. As of release 5.0.8, use custom attributes (org.zkoss.zul.listbox.preloadSize) instead. Returns the number of rows to preload when receiving the rendering request from the client. Default: 50. (since 6.0.1) It is used only if live data ( Note: if the "pre-load-size" attribute of component is specified, it's prior to the original value.(@since 3.0.4) |
|
|
getRowRenderer()
Returns the renderer to render each row, or null if the default renderer is used. |
|
Rows |
getRows()
Returns the rows. |
|
java.lang.String |
getZclass()
Returns the ZK Cascading Style class(es) for this component. |
|
boolean |
insertBefore(Component newChild,
Component refChild)
Inserts a child before the reference child. |
|
protected boolean |
isAutohidePaging()
|
|
boolean |
isFixedLayout()
Deprecated. since 5.0.0, use ! MeshElement.isSizedByContent() instead |
|
boolean |
isVflex()
Returns whether to grow and shrink vertical to fit their given space, so called vertical flexibility. |
|
void |
onInitRender()
Handles a private event, onInitRender. |
|
void |
onPageAttached(Page newpage,
Page oldpage)
Default: handles special event listeners. |
|
void |
onPagingInitRender()
Handles a private event, onPagingInitRender. |
|
protected Paginal |
pgi()
Returns the instance of the @{link Paginal} |
|
boolean |
removeChild(Component child)
Removes a child. |
|
void |
renderAll()
Renders all Row if not loaded yet,
with getRowRenderer() . |
|
void |
renderItems(java.util.Set<? extends Row> rows)
|
|
protected void |
renderProperties(ContentRenderer renderer)
Renders the content of this component, excluding the enclosing tags and children. |
|
void |
renderRow(Row row)
Renders the specified Row if not loaded yet,
with getRowRenderer() . |
|
void |
renderRows(java.util.Set<? extends Row> rows)
Renders a set of specified rows. |
|
void |
service(AuRequest request,
boolean everError)
Processes an AU request. |
|
void |
sessionDidActivate(Page page)
Notification that the session, which owns this component, has just been activated (a.k.a., deserialized). |
|
void |
sessionWillPassivate(Page page)
Notification that the session, which owns this component, is about to be passivated (a.k.a., serialized). |
|
void |
setAlign(java.lang.String align)
Deprecated. As of release 5.0, use CSS instead. |
|
void |
setEmptyMessage(java.lang.String emptyMessage)
|
|
void |
setFixedLayout(boolean fixedLayout)
Deprecated. since 5.0.0, use MeshElement.setSizedByContent(boolean) (!fixedLayout) instead |
|
void |
setInnerWidth(java.lang.String innerWidth)
Sets the inner width of this component. |
|
void |
setModel(GroupsModel<?,?,?> model)
Sets the groups model associated with this grid. |
|
void |
setModel(ListModel<?> model)
Sets the list model associated with this grid. |
|
void |
setMold(java.lang.String mold)
Sets the mold to render this component. |
|
void |
setOddRowSclass(java.lang.String scls)
Sets the style class for the odd rows. |
|
void |
setPaginal(Paginal pgi)
Specifies the paging controller. |
|
void |
setPreloadSize(int sz)
Deprecated. As of release 5.0.8, use custom attributes (org.zkoss.zul.listbox.preloadSize) instead. Sets the number of rows to preload when receiving the rendering request from the client. It is used only if live data ( |
|
void |
setRowRenderer(RowRenderer<?> renderer)
Sets the renderer which is used to render each row if getModel() is not null. |
|
void |
setRowRenderer(java.lang.String clsnm)
Sets the renderer by use of a class name. |
|
void |
setVflex(boolean vflex)
Sets whether to grow and shrink vertical to fit their given space, so called vertical flexibility. |
Methods inherited from class org.zkoss.zul.impl.MeshElement |
---|
getActivePage, getPageCount, getPageSize, getPagingPosition, getSpan, isAutopaging, isSizedByContent, isSpan, setActivePage, setAutopaging, setPageSize, setPagingPosition, setSizedByContent, setSpan, setSpan |
Methods inherited from class org.zkoss.zul.impl.XulElement |
---|
getContext, getCtrlKeys, getPopup, getTooltip, setContext, setContext, setCtrlKeys, setPopup, setPopup, setTooltip, setTooltip |
Methods inherited from class org.zkoss.zk.ui.HtmlBasedComponent |
---|
focus, getAction, getDraggable, getDroppable, getHeight, getHflex, getLeft, getRenderdefer, getSclass, getStyle, getTooltiptext, getTop, getVflex, getWidth, getZindex, getZIndex, setAction, setClass, setDraggable, setDroppable, setFocus, setHeight, setHeightDirectly, setHflex, setHflexDirectly, setLeft, setLeftDirectly, setRenderdefer, setSclass, setStyle, setTooltiptext, setTop, setTopDirectly, setVflex, setWidth, setWidthDirectly, setZclass, setZindex, setZIndex, setZIndexDirectly |
Methods inherited from class java.lang.Object |
---|
finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public Grid()
Method Detail |
---|
public void onPageAttached(Page newpage, Page oldpage)
AbstractComponent
onPageAttached
in interface ComponentCtrl
onPageAttached
in class AbstractComponent
newpage
- the new page (never null).oldpage
- the previous page, if any, or null if it didn't
belong to any page.ComponentCtrl.onPageAttached(org.zkoss.zk.ui.Page, org.zkoss.zk.ui.Page)
public boolean isVflex()
Default: false.
public void setVflex(boolean vflex)
public void setFixedLayout(boolean fixedLayout)
MeshElement.setSizedByContent(boolean)
(!fixedLayout) instead
fixedLayout
- true to outline this grid by browserpublic boolean isFixedLayout()
MeshElement.isSizedByContent()
instead
public Rows getRows()
public Columns getColumns()
public Foot getFoot()
public Frozen getFrozen()
public java.util.Collection<Component> getHeads()
getColumns()
and auxiliary heads (Auxhead
) (never null).
public Component getCell(int row, int col)
row
- which row to fetch (starting at 0).col
- which column to fetch (starting at 0).public java.lang.String getAlign()
public void setAlign(java.lang.String align)
public Paginal getPaginal()
AbstractComponent.getMold()
is "paging".
If mold is "paging", this method never returns null, because
a child paging controller is created automatically (if not specified
by developers with setPaginal(org.zkoss.zul.ext.Paginal)
).
If a paging controller is specified (either by setPaginal(org.zkoss.zul.ext.Paginal)
,
or by setMold(java.lang.String)
with "paging"),
the grid will rely on the paging controller to handle long-content
instead of scrolling.
public void setPaginal(Paginal pgi)
AbstractComponent.getMold()
is "paging".
It is OK, though without any effect, to specify a paging controller even if mold is not "paging".
pgi
- the paging controller. If null and AbstractComponent.getMold()
is "paging",
a paging controller is created automatically as a child component
(see getPagingChild()
).public Paging getPagingChild()
setPaginal(org.zkoss.zul.ext.Paginal)
.
protected Paginal pgi()
MeshElement
pgi
in class MeshElement
public <T> ListModel<T> getModel()
Note: if setModel(GroupsModel)
was called with a
groups model, this method returns an instance of ListModel
encapsulating it.
setModel(ListModel)
,
setModel(GroupsModel)
public <T> ListModel<T> getListModel()
GroupsModel
or not associated with any list data model.
setModel(ListModel)
public <D,G,F> GroupsModel<D,G,F> getGroupsModel()
ListModel
or not associated with any list data model.
setModel(GroupsModel)
public void setModel(ListModel<?> model)
model
- the list model to associate, or null to dissociate
any previous model.
UiException
- if failed to initialize with the modelgetListModel()
,
setModel(GroupsModel)
public void setModel(GroupsModel<?,?,?> model)
The groups model is used to represent a list of data with grouping.
model
- the groups model to associate, or null to dissociate
any previous model.
UiException
- if failed to initialize with the modelsetModel(ListModel)
,
getGroupsModel()
public <T> RowRenderer<T> getRowRenderer()
public void setRowRenderer(RowRenderer<?> renderer)
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.
renderer
- the renderer, or null to use the default.
UiException
- if failed to initialize with the modelpublic void setRowRenderer(java.lang.String clsnm) throws java.lang.ClassNotFoundException, java.lang.NoSuchMethodException, java.lang.IllegalAccessException, java.lang.InstantiationException, java.lang.reflect.InvocationTargetException
java.lang.ClassNotFoundException
java.lang.NoSuchMethodException
java.lang.IllegalAccessException
java.lang.InstantiationException
java.lang.reflect.InvocationTargetException
public int getPreloadSize()
Default: 50. (since 6.0.1)
It is used only if live data (setModel(ListModel)
and
not paging (getPagingChild()
.
Note: if the "pre-load-size" attribute of component is specified, it's prior to the original value.(@since 3.0.4)
public void setPreloadSize(int sz)
It is used only if live data (setModel(ListModel)
and
not paging (getPagingChild()
.
sz
- the number of rows to preload. If zero, no preload
at all.
UiException
- if sz is negativepublic void setInnerWidth(java.lang.String innerWidth)
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 (getInnerWidth()
),
and then restore them when re-creating this component.
innerWidth
- the inner width. If null, "100%" is assumed.public java.lang.String getInnerWidth()
Default: "100%"
setInnerWidth(java.lang.String)
public void onInitRender()
public void onPagingInitRender()
public void renderRow(Row row)
Row
if not loaded yet,
with getRowRenderer()
.
It does nothing if getModel()
returns null.
In other words, it is meaningful only if live data model is used.
public void renderAll()
Row
if not loaded yet,
with getRowRenderer()
.
public void renderRows(java.util.Set<? extends Row> rows)
renderItems(java.util.Set extends org.zkoss.zul.Row>)
.
public void renderItems(java.util.Set<? extends Row> rows)
public java.lang.String getOddRowSclass()
Default: getZclass()
-odd. (since 3.5.0)
public void setOddRowSclass(java.lang.String scls)
public void setMold(java.lang.String mold)
setMold
in interface Component
setMold
in class AbstractComponent
mold
- the mold. If null or empty, "default" is assumed.
Allowed values: default, pagingComponentDefinition
public java.lang.String getZclass()
HtmlBasedComponent
AbstractComponent.getMold()
).
Default: null (the default value depends on element).
HtmlBasedComponent.setZclass(java.lang.String)
) will completely replace the default style
of a component. In other words, the default style of a component
is associated with the default value of HtmlBasedComponent.getZclass()
.
Once it is changed, the default style won't be applied at all.
If you want to perform small adjustments, use HtmlBasedComponent.setSclass(java.lang.String)
instead.
getZclass
in class HtmlBasedComponent
HtmlBasedComponent.getSclass()
public void beforeChildAdded(Component newChild, Component refChild)
AbstractComponent
beforeChildAdded
in interface ComponentCtrl
beforeChildAdded
in class AbstractComponent
newChild
- the child to be added (never null).refChild
- another child component that the new child
will be inserted before it. If null, the new child will be the
last child.ComponentCtrl.beforeChildAdded(org.zkoss.zk.ui.Component, org.zkoss.zk.ui.Component)
public boolean insertBefore(Component newChild, Component refChild)
Component
You could use Component.setParent(org.zkoss.zk.ui.Component)
or Component.appendChild(org.zkoss.zk.ui.Component)
instead of this method, unless
you want to control where to put the child.
Note: Component.setParent(org.zkoss.zk.ui.Component)
always calls back Component.insertBefore(org.zkoss.zk.ui.Component, org.zkoss.zk.ui.Component)
and/or Component.removeChild(org.zkoss.zk.ui.Component)
,
while Component.insertBefore(org.zkoss.zk.ui.Component, org.zkoss.zk.ui.Component)
and Component.removeChild(org.zkoss.zk.ui.Component)
always calls back Component.setParent(org.zkoss.zk.ui.Component)
,
if the parent is changed. Thus, you don't need to override
both Component.insertBefore(org.zkoss.zk.ui.Component, org.zkoss.zk.ui.Component)
and Component.setParent(org.zkoss.zk.ui.Component)
, if you want
to customize the behavior.
If you would like to monitor if a component is attached or detached
from a page, you could register a desktop listener implementing
UiLifeCycle
.
insertBefore
in interface Component
insertBefore
in class AbstractComponent
newChild
- the new child to be inserted.refChild
- the child before which you want the new child
being inserted. If null, the new child is append to the end.
public boolean removeChild(Component child)
Component
Component.detach()
) and it will be removed
if it is no longer used.
You could use Component.setParent(org.zkoss.zk.ui.Component)
with null instead of this method.
Note: Component.setParent(org.zkoss.zk.ui.Component)
always calls back Component.insertBefore(org.zkoss.zk.ui.Component, org.zkoss.zk.ui.Component)
and/or Component.removeChild(org.zkoss.zk.ui.Component)
,
while Component.insertBefore(org.zkoss.zk.ui.Component, org.zkoss.zk.ui.Component)
and Component.removeChild(org.zkoss.zk.ui.Component)
always calls back Component.setParent(org.zkoss.zk.ui.Component)
,
if the parent is changed. Thus, you don't need to override
both Component.insertBefore(org.zkoss.zk.ui.Component, org.zkoss.zk.ui.Component)
and Component.setParent(org.zkoss.zk.ui.Component)
, if you want
to customize the behavior.
If you would like to monitor if a component is attached or detached
from a page, you could register a desktop listener implementing
UiLifeCycle
.
removeChild
in interface Component
removeChild
in class AbstractComponent
protected boolean isAutohidePaging()
isAutohidePaging
in class MeshElement
public java.lang.Object clone()
Component
clone
in interface Component
clone
in class XulElement
public java.lang.String getEmptyMessage()
public void setEmptyMessage(java.lang.String emptyMessage)
protected void renderProperties(ContentRenderer renderer) throws java.io.IOException
HtmlBasedComponent
See also ZK Client-side Reference: Property Rendering
renderProperties
in class MeshElement
java.io.IOException
public void sessionWillPassivate(Page page)
ComponentCtrl
Note: only root components are notified by this method.
sessionWillPassivate
in interface ComponentCtrl
sessionWillPassivate
in class AbstractComponent
public void sessionDidActivate(Page page)
ComponentCtrl
Note: only root components are notified by this method.
sessionDidActivate
in interface ComponentCtrl
sessionDidActivate
in class AbstractComponent
public java.lang.Object getExtraCtrl()
HtmlBasedComponent
Default: creates an instance of HtmlBasedComponent.ExtraCtrl
.
getExtraCtrl
in interface ComponentCtrl
getExtraCtrl
in class HtmlBasedComponent
Cropper
.ComponentCtrl.getExtraCtrl()
public void service(AuRequest request, boolean everError)
Default: in addition to what are handled by HtmlBasedComponent.service(org.zkoss.zk.au.AuRequest, boolean)
,
it also handles onSelect.
service
in interface ComponentCtrl
service
in class HtmlBasedComponent
everError
- whether any error ever occurred before
processing this request.AbstractComponent.setAuService(org.zkoss.zk.au.AuService)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |