com.vaadin.ui.components.grid
Class Grid

java.lang.Object
  extended by com.vaadin.server.AbstractClientConnector
      extended by com.vaadin.ui.AbstractComponent
          extended by com.vaadin.ui.components.grid.Grid
All Implemented Interfaces:
MethodEventSource, ClientConnector, Sizeable, com.vaadin.shared.Connector, Component, java.io.Serializable

public class Grid
extends AbstractComponent

Data grid component

Lazy loading

TODO To be revised when the data data source implementation has been don.

Columns

The grid columns are based on the property ids of the underlying data source. Each property id represents one column in the grid. To retrive a column in the grid you can use getColumn(Object) with the property id of the column. A grid column contains properties like the width, the footer and header captions of the column.

Auxiliary headers and footers

TODO To be revised when column grouping is implemented.

Since:
7.2
Author:
Vaadin Ltd
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from interface com.vaadin.ui.Component
Component.ErrorEvent, Component.Event, Component.Focusable, Component.Listener
 
Nested classes/interfaces inherited from interface com.vaadin.server.ClientConnector
ClientConnector.AttachEvent, ClientConnector.AttachListener, ClientConnector.ConnectorErrorEvent, ClientConnector.DetachEvent, ClientConnector.DetachListener
 
Nested classes/interfaces inherited from interface com.vaadin.server.Sizeable
Sizeable.Unit
 
Field Summary
 
Fields inherited from interface com.vaadin.server.Sizeable
SIZE_UNDEFINED, UNITS_CM, UNITS_EM, UNITS_EX, UNITS_INCH, UNITS_MM, UNITS_PERCENTAGE, UNITS_PICAS, UNITS_PIXELS, UNITS_POINTS
 
Constructor Summary
Grid(Container.Indexed datasource)
          Creates a new Grid using the given datasource.
 
Method Summary
 ColumnGroupRow addColumnGroupRow()
           Adds a new column group to the grid.
 ColumnGroupRow addColumnGroupRow(int rowIndex)
          Adds a new column group to the grid at a specific index
 GridColumn getColumn(java.lang.Object propertyId)
          Returns a column based on the property id
 java.util.List<ColumnGroupRow> getColumnGroupRows()
          Gets the column group rows.
 Container.Indexed getContainerDatasource()
          Returns the grid data source.
 double getHeightByRows()
          Gets the amount of rows in Grid's body that are shown, while getHeightMode() is HeightMode.ROW.
 com.vaadin.shared.ui.grid.HeightMode getHeightMode()
          Returns the current HeightMode the Grid is in.
 java.lang.Object getLastFrozenPropertyId()
          Gets the rightmost frozen column in the grid.
protected  com.vaadin.shared.ui.grid.GridState getState()
          Returns the shared state bean with information to be sent from the server to the client.
protected  com.vaadin.shared.ui.grid.GridState getState(boolean markAsDirty)
          Returns the shared state for this connector.
 boolean isColumnFootersVisible()
          Are the footer rows visible.
 boolean isColumnHeadersVisible()
          Are the header rows visible?
 void removeColumnGroupRow(ColumnGroupRow row)
          Removes a column group.
 void scrollToEnd()
          Scrolls to the end of the last data row.
 void scrollToItem(java.lang.Object itemId)
          Scrolls to a certain item, using ScrollDestination.ANY.
 void scrollToItem(java.lang.Object itemId, com.vaadin.shared.ui.grid.ScrollDestination destination)
          Scrolls to a certain item, using user-specified scroll destination.
 void scrollToStart()
          Scrolls to the beginning of the first data row.
 void setColumnFootersVisible(boolean visible)
          Sets the footer rows visible.
 void setColumnHeadersVisible(boolean visible)
          Sets the header rows visible.
 void setContainerDatasource(Container.Indexed container)
          Sets the grid data source.
 void setHeight(float height, Sizeable.Unit unit)
          Sets the height of the object.
 void setHeightByRows(double rows)
          Sets the number of rows that should be visible in Grid's body, while getHeightMode() is HeightMode.ROW.
 void setHeightMode(com.vaadin.shared.ui.grid.HeightMode heightMode)
          Defines the mode in which the Grid widget's height is calculated.
 void setLastFrozenPropertyId(java.lang.Object propertyId)
          Sets (or unsets) the rightmost frozen column in the grid.
 
Methods inherited from class com.vaadin.ui.AbstractComponent
addListener, addShortcutListener, addStyleName, attach, beforeClientResponse, detach, findAncestor, fireComponentErrorEvent, fireComponentEvent, focus, getActionManager, getCaption, getComponentError, getData, getDebugId, getDescription, getErrorMessage, getHeight, getHeightUnits, getIcon, getId, getLocale, getParent, getPrimaryStyleName, getStyleName, getWidth, getWidthUnits, isConnectorEnabled, isEnabled, isImmediate, isReadOnly, isVisible, removeListener, removeShortcutListener, removeStyleName, setCaption, setComponentError, setData, setDebugId, setDescription, setEnabled, setHeight, setIcon, setId, setImmediate, setLocale, setParent, setPrimaryStyleName, setReadOnly, setSizeFull, setSizeUndefined, setStyleName, setVisible, setWidth, setWidth
 
Methods inherited from class com.vaadin.server.AbstractClientConnector
addAttachListener, addDetachListener, addExtension, addListener, addListener, addListener, addMethodInvocationToQueue, createState, encodeState, fireEvent, getAllChildrenIterable, getConnectorId, getErrorHandler, getExtensions, getListeners, getResource, getRpcManager, getRpcProxy, getSession, getStateType, getUI, handleConnectorRequest, hasListeners, isAttached, markAsDirty, markAsDirtyRecursive, registerRpc, registerRpc, removeAttachListener, removeDetachListener, removeExtension, removeListener, removeListener, removeListener, removeListener, requestRepaint, requestRepaintAll, retrievePendingRpcCalls, setErrorHandler, setResource
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.vaadin.ui.Component
getUI
 
Methods inherited from interface com.vaadin.server.ClientConnector
addAttachListener, addDetachListener, encodeState, getErrorHandler, getExtensions, getRpcManager, getStateType, handleConnectorRequest, isAttached, markAsDirty, markAsDirtyRecursive, removeAttachListener, removeDetachListener, removeExtension, requestRepaint, requestRepaintAll, retrievePendingRpcCalls, setErrorHandler
 
Methods inherited from interface com.vaadin.shared.Connector
getConnectorId
 

Constructor Detail

Grid

public Grid(Container.Indexed datasource)
Creates a new Grid using the given datasource.

Parameters:
datasource - the data source for the grid
Method Detail

setContainerDatasource

public void setContainerDatasource(Container.Indexed container)
Sets the grid data source.

Parameters:
container - The container data source. Cannot be null.
Throws:
java.lang.IllegalArgumentException - if the data source is null

getContainerDatasource

public Container.Indexed getContainerDatasource()
Returns the grid data source.

Returns:
the container data source of the grid

getColumn

public GridColumn getColumn(java.lang.Object propertyId)
Returns a column based on the property id

Parameters:
propertyId - the property id of the column
Returns:
the column or null if not found

setColumnHeadersVisible

public void setColumnHeadersVisible(boolean visible)
Sets the header rows visible.

Parameters:
visible - true if the header rows should be visible

isColumnHeadersVisible

public boolean isColumnHeadersVisible()
Are the header rows visible?

Returns:
true if the headers of the columns are visible

setColumnFootersVisible

public void setColumnFootersVisible(boolean visible)
Sets the footer rows visible.

Parameters:
visible - true if the footer rows should be visible

isColumnFootersVisible

public boolean isColumnFootersVisible()
Are the footer rows visible.

Returns:
true if the footer rows should be visible

addColumnGroupRow

public ColumnGroupRow addColumnGroupRow()

Adds a new column group to the grid.

Column group rows are rendered in the header and footer of the grid. Column group rows are made up of column groups which groups together columns for adding a common auxiliary header or footer for the columns.

Example usage:

 // Add a new column group row to the grid
 ColumnGroupRow row = grid.addColumnGroupRow();
 
 // Group "Column1" and "Column2" together to form a header in the row
 ColumnGroup column12 = row.addGroup("Column1", "Column2");
 
 // Set a common header for "Column1" and "Column2"
 column12.setHeader("Column 1&2");
 

Returns:
a column group instance you can use to add column groups

addColumnGroupRow

public ColumnGroupRow addColumnGroupRow(int rowIndex)
Adds a new column group to the grid at a specific index

Parameters:
rowIndex - the index of the row
Returns:
a column group instance you can use to add column groups

removeColumnGroupRow

public void removeColumnGroupRow(ColumnGroupRow row)
Removes a column group.

Parameters:
row - the row to remove

getColumnGroupRows

public java.util.List<ColumnGroupRow> getColumnGroupRows()
Gets the column group rows.

Returns:
an unmodifiable list of column group rows

getState

protected com.vaadin.shared.ui.grid.GridState getState()
Description copied from class: AbstractComponent
Returns the shared state bean with information to be sent from the server to the client. Subclasses should override this method and set any relevant fields of the state returned by super.getState().

Overrides:
getState in class AbstractComponent
Returns:
updated component shared state

getState

protected com.vaadin.shared.ui.grid.GridState getState(boolean markAsDirty)
Description copied from class: AbstractClientConnector
Returns the shared state for this connector.

Overrides:
getState in class AbstractComponent
Parameters:
markAsDirty - true if the connector should automatically be marked dirty, false otherwise
Returns:
The shared state for this connector. Never null.
See Also:
AbstractClientConnector.getState()

setLastFrozenPropertyId

public void setLastFrozenPropertyId(java.lang.Object propertyId)
Sets (or unsets) the rightmost frozen column in the grid.

All columns up to and including the indicated property will be frozen in place when the grid is scrolled sideways.

Note: If the container used by this grid supports a propertyId null, it can never be defined as the last frozen column, as a null parameter will always reset the frozen columns in Grid.

Parameters:
propertyId - the property id corresponding to the column that should be the last frozen column, or null to not have any columns frozen.
Throws:
java.lang.IllegalArgumentException - if lastFrozenColumn is not a column from this grid

getLastFrozenPropertyId

public java.lang.Object getLastFrozenPropertyId()
Gets the rightmost frozen column in the grid.

Note: Most often, this method returns the very value set with setLastFrozenPropertyId(Object). This value, however, can be reset to null if the column is detached from this grid.

Returns:
the rightmost frozen column in the grid, or null if no columns are frozen.

scrollToItem

public void scrollToItem(java.lang.Object itemId)
                  throws java.lang.IllegalArgumentException
Scrolls to a certain item, using ScrollDestination.ANY.

Parameters:
itemId - id of item to scroll to.
Throws:
java.lang.IllegalArgumentException - if the provided id is not recognized by the data source.

scrollToItem

public void scrollToItem(java.lang.Object itemId,
                         com.vaadin.shared.ui.grid.ScrollDestination destination)
                  throws java.lang.IllegalArgumentException
Scrolls to a certain item, using user-specified scroll destination.

Parameters:
itemId - id of item to scroll to.
destination - value specifying desired position of scrolled-to row.
Throws:
java.lang.IllegalArgumentException - if the provided id is not recognized by the data source.

scrollToStart

public void scrollToStart()
Scrolls to the beginning of the first data row.


scrollToEnd

public void scrollToEnd()
Scrolls to the end of the last data row.


setHeightByRows

public void setHeightByRows(double rows)
Sets the number of rows that should be visible in Grid's body, while getHeightMode() is HeightMode.ROW.

If Grid is currently not in HeightMode.ROW, the given value is remembered, and applied once the mode is applied.

Parameters:
rows - The height in terms of number of rows displayed in Grid's body. If Grid doesn't contain enough rows, white space is displayed instead. If null is given, then Grid's height is undefined
Throws:
java.lang.IllegalArgumentException - if rows is zero or less
java.lang.IllegalArgumentException - if rows is infinite
java.lang.IllegalArgumentException - if rows is NaN

getHeightByRows

public double getHeightByRows()
Gets the amount of rows in Grid's body that are shown, while getHeightMode() is HeightMode.ROW.

Returns:
the amount of rows that are being shown in Grid's body
See Also:
setHeightByRows(double)

setHeight

public void setHeight(float height,
                      Sizeable.Unit unit)
Sets the height of the object. Negative number implies unspecified size (terminal is free to set the size).

Note: This method will change the widget's size in the browser only if getHeightMode() returns HeightMode.CSS.

Specified by:
setHeight in interface Sizeable
Overrides:
setHeight in class AbstractComponent
Parameters:
height - the height of the object.
unit - the unit used for the width.
See Also:
setHeightMode(HeightMode)

setHeightMode

public void setHeightMode(com.vaadin.shared.ui.grid.HeightMode heightMode)
Defines the mode in which the Grid widget's height is calculated.

If HeightMode.CSS is given, Grid will respect the values given via a setHeight-method, and behave as a traditional Component.

If HeightMode.ROW is given, Grid will make sure that the body will display as many rows as getHeightByRows() defines. Note: If headers/footers are inserted or removed, the widget will resize itself to still display the required amount of rows in its body. It also takes the horizontal scrollbar into account.

Parameters:
heightMode - the mode in to which Grid should be set

getHeightMode

public com.vaadin.shared.ui.grid.HeightMode getHeightMode()
Returns the current HeightMode the Grid is in.

Defaults to HeightMode.CSS.

Returns:
the current HeightMode


Copyright © 2000-2011 Vaadin Ltd. All Rights Reserved.