com.extjs.gxt.ui.client.widget.grid
Class Grid<M extends ModelData>

java.lang.Object
  extended by com.google.gwt.user.client.ui.UIObject
      extended by com.google.gwt.user.client.ui.Widget
          extended by com.extjs.gxt.ui.client.widget.Component
              extended by com.extjs.gxt.ui.client.widget.BoxComponent
                  extended by com.extjs.gxt.ui.client.widget.grid.Grid<M>
Type Parameters:
M - the model type
All Implemented Interfaces:
Observable, com.google.gwt.event.shared.HasHandlers, com.google.gwt.user.client.EventListener
Direct Known Subclasses:
EditorGrid, TreeGrid

public class Grid<M extends ModelData>
extends BoxComponent

This class represents the primary interface of a component based grid control. The grid requires a ListStore and ColumnModel when constructed. Each model in the store will be rendered as a row in the grid. Any updates to the store are automatically pushed to the grid. This includes inserting, removing, sorting and filter.

Grid support several ways to manage column widths.

  1. The most basic approach is to simply give pixel widths to each column. Columns widths will match the specified values.
  2. A column can be set to "fill" all available space. As the width of the grid changes, or columns are resized, the "filling" column's width is adjusted so that the column's fill the available width with no horizontal scrolling. See @link setAutoExpandColumn(String).
  3. Grid can resize columns based on a "weight". As the width of the grid, or columns change, the "weight" is used to allocate the extra space, or the space needed to be reduced. Use GridView.setAutoFill(boolean) to enable this feature. With auto fill, the calculations are only run once. After the grid is rendered, the columns widths will not be adjusted when available width changes. You can use @link GridView.setForceFit(boolean) to always run the width calculations on any changes to available width or column sizes. Columns can be "fixed" which prevents their columns widths to be adjusted by the grid "weight" calculations. See @link ColumnConfig.setFixed(boolean).

When state is enabled (default is false), Grid will save and restore the column width, column hidden state, sort direction, and sort field. To enable state, see Component.setStateful(boolean). When the store uses a PagingListLoader the offset and limit parameter are saved with the Grid's state. These 2 values can be retrieved and used to make the first load request to return the user to the same location they left the grid. Code snippet:

      PagingLoadConfig config = new BasePagingLoadConfig();
      config.setOffset(0);
      config.setLimit(50);

      Map state = grid.getState();
      if (state.containsKey("offset")) {
        int offset = (Integer)state.get("offset");
        int limit = (Integer)state.get("limit");
        config.setOffset(offset);
        config.setLimit(limit);
      }
      if (state.containsKey("sortField")) {
        config.setSortField((String)state.get("sortField"));
        config.setSortDir(SortDir.valueOf((String)state.get("sortDir")));
      }
      loader.load(config);
 
Events:
CellClick : GridEvent(grid, rowIndex, cellIndex, event)
Fires after a cell is clicked.
CellDoubleClick : GridEvent(grid, rowIndex, cellIndex, event)
Fires after a cell is double clicked.
CellMouseDown : GridEvent(grid, rowIndex, cellIndex, event)
Fires before a cell is clicked.
RowClick : GridEvent(grid, rowIndex, cellIndex, event)
Fires after a row is clicked.
RowDoubleClick : GridEvent(grid, rowIndex, cellIndex, event)
Fires after a row is double clicked.
RowMouseDown : GridEvent(grid, rowIndex, colIndex, event)
Fires before a row is clicked.
HeaderClick : GridEvent(grid, rowIndex, colIndex, event)
Fires a header is clicked.
HeaderDoubleClick : GridEvent(grid, rowIndex, colIndex, event)
Fires a header is double clicked.
HeaderMouseDown : GridEvent(grid, rowIndex, colIndex, event)
Fires before a header is clicked.
ContextMenu : GridEvent(grid)
Fires before the grid's context menu is shown. Listeners can cancel the action by calling BaseEvent.setCancelled(boolean).
HeaderContextMenu : TableEvent(grid, colIndex, menu)
Fires right before the header's context menu is displayed.
BodyScroll : GridEvent(grid, srollLeft, scrollTop)
Fires when the body element is scrolled.
ColumnResize : GridEvent(grid, colIndex, width)
Fires when the user resizes a column.
ColumnMove : GridEvent(grid, colIndex, size)
Fires when the user moves a column.
SortChange : GridEvent(grid, sortInfo)
Fires when the grid's store sort changes.
ViewReady : GridEvent(grid)
Fires when the grid's view is ready.
Inherited Events:
BoxComponent Move
BoxComponent Resize
Component Enable
Component Disable
Component BeforeHide
Component Hide
Component BeforeShow
Component Show
Component Attach
Component Detach
Component BeforeRender
Component Render
Component BrowserEvent
Component BeforeStateRestore
Component StateRestore
Component BeforeStateSave
Component SaveState


Nested Class Summary
 
Nested classes/interfaces inherited from class com.google.gwt.user.client.ui.UIObject
com.google.gwt.user.client.ui.UIObject.DebugIdImpl, com.google.gwt.user.client.ui.UIObject.DebugIdImplEnabled
 
Field Summary
 
Fields inherited from class com.google.gwt.user.client.ui.UIObject
DEBUG_ID_PREFIX
 
Constructor Summary
Grid(ListStore<M> store, ColumnModel cm)
          Creates a new grid.
 
Method Summary
 java.lang.String getAutoExpandColumn()
          Returns the auto expand column id.
 int getAutoExpandMax()
          Returns the auto expand maximum width.
 int getAutoExpandMin()
          Returns the auto expand miniumum width.
 ColumnModel getColumnModel()
          Returns the column model.
 int getLazyRowRender()
          Returns the time in ms after the rows get rendered.
 int getMinColumnWidth()
          Returns the minimum column width.
 GridSelectionModel<M> getSelectionModel()
          Returns the grid's selection model.
 ListStore<M> getStore()
          Returns the grid's store.
 GridView getView()
          Returns the grid's view.
 boolean isEnableColumnResize()
          Returns true if column resizing is enabled.
 boolean isHideHeaders()
          Returns true if the header is hidden.
 boolean isLoadMask()
          Returns true if the load mask in enabled.
 boolean isStripeRows()
          Returns true if row striping is enabled.
 boolean isTrackMouseOver()
          Returns true if rows are highlighted on mouse over.
 boolean isViewReady()
          Returns true if the view is ready.
 void onComponentEvent(ComponentEvent ce)
          Any events a component receives will be forwarded to this method.
 void reconfigure(ListStore<M> store, ColumnModel cm)
          Reconfigures the grid to use a different Store and Column Model.
 void setAutoExpandColumn(java.lang.String autoExpandColumn)
          The id of a column in this grid that should expand to fill unused space (pre-render).
 void setAutoExpandMax(int autoExpandMax)
          The maximum width the autoExpandColumn can have (if enabled) (defaults to 1000, pre-render).
 void setAutoExpandMin(int autoExpandMin)
          The minimum width the autoExpandColumn can have (if enabled)(pre-render).
 void setEnableColumnResize(boolean enableColumnResize)
          Sets whether columns may be resized (defaults to true).
 void setHideHeaders(boolean hideHeaders)
          Sets whether the header should be hidden (defaults to false).
 void setLazyRowRender(int lazyRowRender)
          Sets the time in ms after the row gets rendered (defaults to 10).
 void setLoadMask(boolean loadMask)
          Sets whether a load mask should be displayed during load operations (defaults to false).
 void setMinColumnWidth(int minColumnWidth)
          The minimum width a column can be resized to (defaults to 25).
 void setSelectionModel(GridSelectionModel<M> sm)
          Sets the grid selection model.
 void setStringProvider(ModelStringProvider<M> stringProvider)
          Sets the binder's string provider.
 void setStripeRows(boolean stripeRows)
          True to stripe the rows (defaults to false).
 void setTrackMouseOver(boolean trackMouseOver)
          True to highlight rows when the mouse is over (defaults to true).
 void setView(GridView view)
          Sets the view's grid (pre-render).
 
Methods inherited from class com.extjs.gxt.ui.client.widget.BoxComponent
getBounds, getHeight, getHeight, getPosition, getShadow, getShadowOffset, getShadowPosition, getSize, getWidth, getWidth, isAutoHeight, isAutoWidth, isDeferHeight, isShim, setAutoHeight, setAutoWidth, setBounds, setBounds, setDeferHeight, setHeight, setHeight, setPagePosition, setPagePosition, setPixelSize, setPosition, setShadow, setShadowOffset, setShadowPosition, setShim, setSize, setSize, setWidth, setWidth, sync, syncSize
 
Methods inherited from class com.extjs.gxt.ui.client.widget.Component
addListener, addPlugin, addStyleName, addWidgetListener, clearState, disable, disableEvents, disableTextSelection, el, enable, enableEvents, fireEvent, fireEvent, fireEvent, fly, focus, getBaseStyle, getBorders, getContextMenu, getData, getElement, getHideMode, getId, getItemId, getListeners, getModel, getState, getStateId, getToolTip, hasListeners, hasListeners, hide, hideToolTip, isDisabledEvents, isEnabled, isRendered, isStateful, isVisible, mask, mask, mask, onBrowserEvent, recalculate, removeAllListeners, removeFromParent, removeListener, removeStyleName, removeSwallow, removeToolTip, removeWidgetListener, render, render, repaint, saveState, setBorders, setContextMenu, setData, setElement, setEnabled, setHideMode, setId, setIntStyleAttribute, setItemId, setStateful, setStateId, setStyleAttribute, setStyleName, setTitle, setToolTip, setToolTip, setVisible, setZIndex, show, sinkEvents, swallowEvent, swallowEvent, toString, unmask
 
Methods inherited from class com.google.gwt.user.client.ui.Widget
fireEvent, getParent, isAttached
 
Methods inherited from class com.google.gwt.user.client.ui.UIObject
addStyleDependentName, ensureDebugId, ensureDebugId, getAbsoluteLeft, getAbsoluteTop, getOffsetHeight, getOffsetWidth, getStyleName, getStylePrimaryName, getTitle, isVisible, removeStyleDependentName, setStylePrimaryName, setVisible, unsinkEvents
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Grid

public Grid(ListStore<M> store,
            ColumnModel cm)
Creates a new grid.

Parameters:
store - the data store
cm - the column model
Method Detail

getAutoExpandColumn

public java.lang.String getAutoExpandColumn()
Returns the auto expand column id.

Returns:
the auto expand column id

getAutoExpandMax

public int getAutoExpandMax()
Returns the auto expand maximum width.

Returns:
the max width in pixels

getAutoExpandMin

public int getAutoExpandMin()
Returns the auto expand miniumum width.

Returns:
the minimum width in pixels

getColumnModel

public ColumnModel getColumnModel()
Returns the column model.

Returns:
the colum model

getLazyRowRender

public int getLazyRowRender()
Returns the time in ms after the rows get rendered.

Returns:
the lazy row rendering time

getMinColumnWidth

public int getMinColumnWidth()
Returns the minimum column width.

Returns:
the min width in pixels

getSelectionModel

public GridSelectionModel<M> getSelectionModel()
Returns the grid's selection model.

Returns:
the selection model

getStore

public ListStore<M> getStore()
Returns the grid's store.

Returns:
the store

getView

public GridView getView()
Returns the grid's view.

Returns:
the grid view

isEnableColumnResize

public boolean isEnableColumnResize()
Returns true if column resizing is enabled.

Returns:
true if resizing is enabled

isHideHeaders

public boolean isHideHeaders()
Returns true if the header is hidden.

Returns:
true for hidden

isLoadMask

public boolean isLoadMask()
Returns true if the load mask in enabled.

Returns:
the load mask state

isStripeRows

public boolean isStripeRows()
Returns true if row striping is enabled.

Returns:
the strip row state

isTrackMouseOver

public boolean isTrackMouseOver()
Returns true if rows are highlighted on mouse over.

Returns:
the track mouse state

isViewReady

public boolean isViewReady()
Returns true if the view is ready.

Returns:
the view ready state

onComponentEvent

public void onComponentEvent(ComponentEvent ce)
Description copied from class: Component
Any events a component receives will be forwarded to this method. Subclasses should override as needed. The Component.onBrowserEvent(com.google.gwt.user.client.Event) method should not be overridden or modified.

Overrides:
onComponentEvent in class Component
Parameters:
ce - the base event

reconfigure

public void reconfigure(ListStore<M> store,
                        ColumnModel cm)
Reconfigures the grid to use a different Store and Column Model. The View will be bound to the new objects and refreshed.

Parameters:
store - the new store
cm - the new column model

setAutoExpandColumn

public void setAutoExpandColumn(java.lang.String autoExpandColumn)
The id of a column in this grid that should expand to fill unused space (pre-render). This id can not be 0.

Parameters:
autoExpandColumn - the auto expand column id

setAutoExpandMax

public void setAutoExpandMax(int autoExpandMax)
The maximum width the autoExpandColumn can have (if enabled) (defaults to 1000, pre-render).

Parameters:
autoExpandMax - the auto expand max

setAutoExpandMin

public void setAutoExpandMin(int autoExpandMin)
The minimum width the autoExpandColumn can have (if enabled)(pre-render).

Parameters:
autoExpandMin - the auto expand min width

setEnableColumnResize

public void setEnableColumnResize(boolean enableColumnResize)
Sets whether columns may be resized (defaults to true).

Parameters:
enableColumnResize - true to allow column resizing

setHideHeaders

public void setHideHeaders(boolean hideHeaders)
Sets whether the header should be hidden (defaults to false).

Parameters:
hideHeaders - true to hide the header

setLazyRowRender

public void setLazyRowRender(int lazyRowRender)
Sets the time in ms after the row gets rendered (defaults to 10). 0 means that the rows get rendered as soon as the grid gets rendered.

Parameters:
lazyRowRender - the time in ms after the rows get rendered.

setLoadMask

public void setLoadMask(boolean loadMask)
Sets whether a load mask should be displayed during load operations (defaults to false).

Parameters:
loadMask - true to show a mask

setMinColumnWidth

public void setMinColumnWidth(int minColumnWidth)
The minimum width a column can be resized to (defaults to 25).

Parameters:
minColumnWidth - the min column width

setSelectionModel

public void setSelectionModel(GridSelectionModel<M> sm)
Sets the grid selection model.

Parameters:
sm - the selection model

setStringProvider

public void setStringProvider(ModelStringProvider<M> stringProvider)
Sets the binder's string provider.

Parameters:
stringProvider - the string provider

setStripeRows

public void setStripeRows(boolean stripeRows)
True to stripe the rows (defaults to false).

Parameters:
stripeRows - true to strip rows

setTrackMouseOver

public void setTrackMouseOver(boolean trackMouseOver)
True to highlight rows when the mouse is over (defaults to true).

Parameters:
trackMouseOver - true to highlight rows on mouse over

setView

public void setView(GridView view)
Sets the view's grid (pre-render).

Parameters:
view - the view