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.logical.shared.HasAttachHandlers, com.google.gwt.event.shared.HasHandlers, com.google.gwt.user.client.EventListener, com.google.gwt.user.client.ui.IsWidget
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 : GridEvent(grid, colIndex, menu)
Fires right before the header's context menu is displayed. Listeners can cancel the action by calling BaseEvent.setCancelled(boolean).
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.
Reconfigure : GridEvent(grid)
Fires when the grid gets reconfigured.
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
protected  ColumnModel cm
           
protected  EditorSupport<M> editSupport
           
protected  GridSelectionModel<M> sm
           
protected  ListStore<M> store
           
protected  ModelStringProvider<M> stringProvider
           
protected  GridView view
           
protected  boolean viewReady
           
 
Fields inherited from class com.extjs.gxt.ui.client.widget.BoxComponent
adjustSize, cacheSizes, ensureVisibilityOnSizing, height, lastSize, layer, shim, width
 
Fields inherited from class com.extjs.gxt.ui.client.widget.Component
afterRender, attachables, baseStyle, disabled, disabledStyle, disableTextSelection, dummy, focusable, hidden, mask, maskMessage, maskMessageStyleName, monitorWindowResize, rendered, resizeHandler, setElementRender, stateId, swallowEvents, toolTip, windowResizeDelay, windowResizeTask
 
Fields inherited from class com.google.gwt.user.client.ui.UIObject
DEBUG_ID_PREFIX
 
Constructor Summary
protected Grid()
           
  Grid(ListStore<M> store, ColumnModel cm)
          Creates a new grid.
 
Method Summary
protected  void afterRender()
          Called after the component has been rendered and is attached for the first time.
protected  void afterRenderView()
           
protected  void applyState(java.util.Map<java.lang.String,java.lang.Object> state)
           
protected  ComponentEvent createComponentEvent(com.google.gwt.user.client.Event event)
           
 void disableTextSelection(boolean disable)
          Enables and disables text selection for the component.
protected  void doApplyStoreState(java.util.Map<java.lang.String,java.lang.Object> state)
           
protected  void doAttachChildren()
           
protected  void doDetachChildren()
           
 java.lang.String getAutoExpandColumn()
          Returns the auto expand column id.
 int getAutoExpandMax()
          Returns the auto expand maximum width.
 int getAutoExpandMin()
          Returns the auto expand minimum width.
 ColumnModel getColumnModel()
          Returns the column model.
protected  EditorSupport<M> getEditSupport()
           
protected  El getFocusEl()
           
 int getLazyRowRender()
          Returns the time in ms after the rows get rendered.
 int getMinColumnWidth()
          Returns the minimum column width.
 ModelProcessor<M> getModelProcessor()
          Returns the model processor.
 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 isColumnLines()
          Returns true if column lines are enabled.
 boolean isColumnReordering()
          Returns true if column reordering is enabled.
 boolean isColumnResize()
          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.
protected  void notifyHide()
           
protected  void notifyShow()
           
protected  void onAfterRenderView()
           
protected  void onBlur(ComponentEvent ce)
           
protected  void onClick(GridEvent<M> e)
           
 void onComponentEvent(ComponentEvent ce)
          Any events a component receives will be forwarded to this method.
protected  void onDisable()
           
protected  void onDoubleClick(GridEvent<M> e)
           
protected  void onEnable()
           
protected  void onFocus(ComponentEvent ce)
           
protected  void onMouseDown(GridEvent<M> e)
           
protected  void onMouseUp(GridEvent<M> e)
           
protected  void onRender(com.google.gwt.user.client.Element target, int index)
          Subclasses must override and ensure setElement is called for lazy rendered components.
protected  void onResize(int width, int height)
          Called after the component is resized, this method is empty by default but can be implemented by any subclass that needs to perform custom logic after a resize occurs.
 void reconfigure(ListStore<M> store, ColumnModel cm)
          Reconfigures the grid to use a different Store and Column Model.
protected  void setAriaRole(java.lang.String roleName)
           
protected  void setAriaState(java.lang.String stateName, java.lang.String stateValue)
           
 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 500, pre-render).
 void setAutoExpandMin(int autoExpandMin)
          The minimum width the autoExpandColumn can have (if enabled)(pre-render).
 void setColumnLines(boolean columnLines)
          True to enable column separation lines (defaults to false).
 void setColumnReordering(boolean enableColumnReorder)
          True to enable column reordering via drag and drop (defaults to false).
 void setColumnResize(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 setModelProcessor(ModelProcessor<M> modelProcessor)
          Sets the grid's model processor.
 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).
protected  GridSelectionModel.Cell walkCells(int row, int col, int step, GridSelectionModel.Callback callback, boolean acceptNavs)
           
 
Methods inherited from class com.extjs.gxt.ui.client.widget.BoxComponent
adjustPosition, adjustSize, getBounds, getHeight, getHeight, getPosition, getPositionEl, getResizeEl, getShadow, getShadowOffset, getShadowPosition, getSize, getWidth, getWidth, hideShadow, hideShim, hideUnders, isAutoHeight, isAutoWidth, isDeferHeight, isShim, onHide, onPosition, onShow, onUnload, 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
addAttachable, addListener, addPlugin, addStyleName, addStyleOnOver, addWidgetListener, assertAfterRender, assertPreRender, beforeRender, blur, clearState, createObservable, createStyles, disable, disableContextMenu, disableEvents, el, enable, enableEvents, fireEvent, fireEvent, fireEvent, fly, focus, frame, getAriaSupport, getBaseStyle, getBorders, getContextMenu, getData, getElement, getFocusSupport, getHideMode, getId, getItemId, getListeners, getModel, getObservable, getPlugins, getState, getStateId, getTabIndex, getTitle, getToolTip, getWindowResizeDelay, hasListeners, hasListeners, hide, hideToolTip, initState, isDisabledEvents, isDisableTextSelection, isEnabled, isMasked, isMonitorWindowResize, isRendered, isStateful, isVisible, isVisible, mask, mask, mask, onAttach, onBrowserEvent, onDetach, onDetachHelper, onEnsureDebugId, onHideContextMenu, onLoad, onRightClick, onShowContextMenu, onWindowResize, previewEvent, recalculate, removeAllListeners, removeAttachagle, removeFromParent, removeListener, removeStyleName, removeStyleOnOver, removeSwallow, removeToolTip, removeWidgetListener, render, render, repaint, saveState, setAriaSupport, setBorders, setContextMenu, setData, setEl, setElement, setElement, setEnabled, setFiresEvents, setHideMode, setId, setIntStyleAttribute, setItemId, setModel, setMonitorWindowResize, setParent, setStateful, setStateId, setStyleAttribute, setStyleName, setTabIndex, setTitle, setToolTip, setToolTip, setVisible, setWindowResizeDelay, setZIndex, show, sinkEvents, swallowEvent, swallowEvent, toString, unframe, unmask
 
Methods inherited from class com.google.gwt.user.client.ui.Widget
addAttachHandler, addBitlessDomHandler, addDomHandler, addHandler, asWidget, asWidgetOrNull, createHandlerManager, delegateEvent, fireEvent, getHandlerCount, getLayoutData, getParent, isAttached, isOrWasAttached, setLayoutData
 
Methods inherited from class com.google.gwt.user.client.ui.UIObject
addStyleDependentName, ensureDebugId, ensureDebugId, ensureDebugId, getAbsoluteLeft, getAbsoluteTop, getOffsetHeight, getOffsetWidth, getStyleElement, getStyleName, getStyleName, getStylePrimaryName, getStylePrimaryName, isVisible, removeStyleDependentName, setElement, setStyleDependentName, setStyleName, setStyleName, setStyleName, setStylePrimaryName, setStylePrimaryName, setVisible, sinkBitlessEvent, unsinkEvents
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

cm

protected ColumnModel cm

editSupport

protected EditorSupport<M extends ModelData> editSupport

sm

protected GridSelectionModel<M extends ModelData> sm

store

protected ListStore<M extends ModelData> store

stringProvider

protected ModelStringProvider<M extends ModelData> stringProvider

view

protected GridView view

viewReady

protected boolean viewReady
Constructor Detail

Grid

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

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

Grid

protected Grid()
Method Detail

disableTextSelection

public void disableTextSelection(boolean disable)
Description copied from class: Component
Enables and disables text selection for the component.

Overrides:
disableTextSelection in class Component
Parameters:
disable - true to disable text selection

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 minimum width.

Returns:
the minimum width in pixels

getColumnModel

public ColumnModel getColumnModel()
Returns the column model.

Returns:
the column 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

getModelProcessor

public ModelProcessor<M> getModelProcessor()
Returns the model processor.

Returns:
the model processor

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

isColumnLines

public boolean isColumnLines()
Returns true if column lines are enabled.

Returns:
true if column lines are enabled

isColumnReordering

public boolean isColumnReordering()
Returns true if column reordering is enabled.

Returns:
true if enabled

isColumnResize

public boolean isColumnResize()
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 500, 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

setColumnLines

public void setColumnLines(boolean columnLines)
True to enable column separation lines (defaults to false).

Parameters:
columnLines - true to enable column separation lines

setColumnReordering

public void setColumnReordering(boolean enableColumnReorder)
True to enable column reordering via drag and drop (defaults to false).

Parameters:
enableColumnReorder - true to enable

setColumnResize

public void setColumnResize(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

setModelProcessor

public void setModelProcessor(ModelProcessor<M> modelProcessor)
Sets the grid's model processor.

Parameters:
modelProcessor -
See Also:
ModelProcessor

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

afterRender

protected void afterRender()
Description copied from class: Component
Called after the component has been rendered and is attached for the first time. At this time, the component will be part of the DOM which is required when retrieving location and offsets.

Overrides:
afterRender in class BoxComponent

afterRenderView

protected void afterRenderView()

applyState

protected void applyState(java.util.Map<java.lang.String,java.lang.Object> state)
Overrides:
applyState in class Component

createComponentEvent

protected ComponentEvent createComponentEvent(com.google.gwt.user.client.Event event)
Overrides:
createComponentEvent in class BoxComponent

doApplyStoreState

protected void doApplyStoreState(java.util.Map<java.lang.String,java.lang.Object> state)

doAttachChildren

protected void doAttachChildren()
Overrides:
doAttachChildren in class Component

doDetachChildren

protected void doDetachChildren()
Overrides:
doDetachChildren in class Component

getEditSupport

protected EditorSupport<M> getEditSupport()

getFocusEl

protected El getFocusEl()
Overrides:
getFocusEl in class Component

notifyHide

protected void notifyHide()
Overrides:
notifyHide in class Component

notifyShow

protected void notifyShow()
Overrides:
notifyShow in class Component

onAfterRenderView

protected void onAfterRenderView()

onBlur

protected void onBlur(ComponentEvent ce)

onClick

protected void onClick(GridEvent<M> e)

onDisable

protected void onDisable()
Overrides:
onDisable in class Component

onDoubleClick

protected void onDoubleClick(GridEvent<M> e)

onEnable

protected void onEnable()
Overrides:
onEnable in class Component

onFocus

protected void onFocus(ComponentEvent ce)

onMouseDown

protected void onMouseDown(GridEvent<M> e)

onMouseUp

protected void onMouseUp(GridEvent<M> e)

onRender

protected void onRender(com.google.gwt.user.client.Element target,
                        int index)
Description copied from class: Component
Subclasses must override and ensure setElement is called for lazy rendered components.

Overrides:
onRender in class Component
Parameters:
target - the target element
index - the insert location

onResize

protected void onResize(int width,
                        int height)
Description copied from class: BoxComponent
Called after the component is resized, this method is empty by default but can be implemented by any subclass that needs to perform custom logic after a resize occurs.

Overrides:
onResize in class BoxComponent
Parameters:
width - the width
height - the height

setAriaRole

protected void setAriaRole(java.lang.String roleName)
Overrides:
setAriaRole in class Component

setAriaState

protected void setAriaState(java.lang.String stateName,
                            java.lang.String stateValue)
Overrides:
setAriaState in class Component

walkCells

protected GridSelectionModel.Cell walkCells(int row,
                                            int col,
                                            int step,
                                            GridSelectionModel.Callback callback,
                                            boolean acceptNavs)