com.sencha.gxt.widget.core.client.grid
Class Grid<M>

java.lang.Object
  extended by com.google.gwt.user.client.ui.UIObject
      extended by com.google.gwt.user.client.ui.Widget
          extended by com.sencha.gxt.widget.core.client.Component
              extended by com.sencha.gxt.widget.core.client.grid.Grid<M>
Type Parameters:
M - the model type
All Implemented Interfaces:
HasAttachHandlers, HasResizeHandlers, HasHandlers, EventListener, HasVisibility, IsWidget, BeforeHideEvent.HasBeforeHideHandlers, BeforeShowContextMenuEvent.HasBeforeShowContextMenuHandler, BeforeShowEvent.HasBeforeShowHandlers, BlurEvent.HasBlurHandlers, BodyScrollEvent.HasBodyScrollHandlers, CellClickEvent.HasCellClickHandlers, CellDoubleClickEvent.HasCellDoubleClickHandlers, CellMouseDownEvent.HasCellMouseDownHandlers, DisableEvent.HasDisableHandlers, EnableEvent.HasEnableHandlers, FocusEvent.HasFocusHandlers, HeaderClickEvent.HasHeaderClickHandlers, HeaderContextMenuEvent.HasHeaderContextMenuHandlers, HeaderDoubleClickEvent.HasHeaderDoubleClickHandlers, HeaderMouseDownEvent.HasHeaderMouseDownHandlers, HideEvent.HasHideHandlers, MoveEvent.HasMoveHandlers, ReconfigureEvent.HasReconfigureHandlers, RefreshEvent.HasRefreshHandlers, RowClickEvent.HasRowClickHandlers, RowDoubleClickEvent.HasRowDoubleClickHandlers, RowMouseDownEvent.HasRowMouseDownHandlers, ShowContextMenuEvent.HasShowContextMenuHandler, ShowEvent.HasShowHandlers, SortChangeEvent.HasSortChangeHandlers, ViewReadyEvent.HasViewReadyHandlers, HasFocusSupport, HasItemId
Direct Known Subclasses:
TreeGrid

public class Grid<M>
extends Component
implements ViewReadyEvent.HasViewReadyHandlers, SortChangeEvent.HasSortChangeHandlers, RowClickEvent.HasRowClickHandlers, RowDoubleClickEvent.HasRowDoubleClickHandlers, RowMouseDownEvent.HasRowMouseDownHandlers, CellClickEvent.HasCellClickHandlers, CellDoubleClickEvent.HasCellDoubleClickHandlers, CellMouseDownEvent.HasCellMouseDownHandlers, HeaderClickEvent.HasHeaderClickHandlers, HeaderDoubleClickEvent.HasHeaderDoubleClickHandlers, HeaderContextMenuEvent.HasHeaderContextMenuHandlers, HeaderMouseDownEvent.HasHeaderMouseDownHandlers, RefreshEvent.HasRefreshHandlers, ReconfigureEvent.HasReconfigureHandlers, BodyScrollEvent.HasBodyScrollHandlers

This class represents the primary interface of a widget 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 GridView.setAutoExpandColumn(ColumnConfig).
  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).


Nested Class Summary
static interface Grid.Callback
          Provides a mechanism by which other components can report whether a cell is selectable.
static class Grid.GridCell
          A reference to a cell in the grid that can be used for a variety of purposes, including, for example, whether it is active or selected.
 
Nested classes/interfaces inherited from class com.google.gwt.user.client.ui.UIObject
UIObject.DebugIdImpl, 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<M> cm)
          Creates a new grid with the given data store and column model.
Grid(ListStore<M> store, ColumnModel<M> cm, GridView<M> view)
          Creates a new grid with the given data store and column model.
 
Method Summary
 HandlerRegistration addBodyScrollHandler(BodyScrollEvent.BodyScrollHandler handler)
           
 HandlerRegistration addCellClickHandler(CellClickEvent.CellClickHandler handler)
           
 HandlerRegistration addCellDoubleClickHandler(CellDoubleClickEvent.CellDoubleClickHandler handler)
           
 HandlerRegistration addCellMouseDownHandler(CellMouseDownEvent.CellMouseDownHandler handler)
           
 HandlerRegistration addHeaderClickHandler(HeaderClickEvent.HeaderClickHandler handler)
           
 HandlerRegistration addHeaderContextMenuHandler(HeaderContextMenuEvent.HeaderContextMenuHandler handler)
           
 HandlerRegistration addHeaderDoubleClickHandler(HeaderDoubleClickEvent.HeaderDoubleClickHandler handler)
           
 HandlerRegistration addHeaderMouseDownHandler(HeaderMouseDownEvent.HeaderMouseDownHandler handler)
           
 HandlerRegistration addReconfigureHandler(ReconfigureEvent.ReconfigureHandler handler)
           
 HandlerRegistration addRefreshHandler(RefreshEvent.RefreshHandler handler)
          Adds a RefreshEvent.RefreshHandler handler for RefreshEvent events.
 HandlerRegistration addRowClickHandler(RowClickEvent.RowClickHandler handler)
           
 HandlerRegistration addRowDoubleClickHandler(RowDoubleClickEvent.RowDoubleClickHandler handler)
           
 HandlerRegistration addRowMouseDownHandler(RowMouseDownEvent.RowMouseDownHandler handler)
           
 HandlerRegistration addSortChangeHandler(SortChangeEvent.SortChangeHandler handler)
           
 HandlerRegistration addViewReadyHandler(ViewReadyEvent.ViewReadyHandler handler)
           
 ColumnModel<M> getColumnModel()
          Returns the column model.
 int getLazyRowRender()
          Returns the time in ms after the rows get rendered.
 ListLoader<?,?> getLoader()
          Returns the loader.
 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<M> getView()
          Returns the grid's view.
 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 isViewReady()
          Returns true if the view is ready.
 void onBrowserEvent(Event ce)
           
 void reconfigure(ListStore<M> store, ColumnModel<M> cm)
          Reconfigures the grid to use a different Store and Column Model.
 void setAllowTextSelection(boolean enable)
          Enables and disables text selection for the widget.
 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 setLoader(ListLoader<?,?> loader)
          Sets the loader.
 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 setView(GridView<M> view)
          Sets the view's grid (pre-render).
 Grid.GridCell walkCells(int row, int col, int step, Grid.Callback callback)
          Navigate in the requested direction to the next selectable cell, given the row, column and step.
 
Methods inherited from class com.sencha.gxt.widget.core.client.Component
addBeforeHideHandler, addBeforeShowContextMenuHandler, addBeforeShowHandler, addBlurHandler, addDisableHandler, addEnableHandler, addFocusHandler, addHideHandler, addMoveHandler, addResizeHandler, addShowContextMenuHandler, addShowHandler, addStyleOnOver, clearSizeCache, disable, disableEvents, enable, enableEvents, fireEvent, focus, getData, getElement, getFocusSupport, getHideMode, getId, getItemId, getOffsetHeight, getOffsetWidth, getShadow, getStateId, getToolTip, hide, hideToolTip, isAllowTextSelection, isAutoHeight, isAutoWidth, isDeferHeight, isEnabled, isRendered, isStateful, isVisible, isVisible, mask, mask, removeToolTip, setBorders, setBounds, setBounds, setContextMenu, setData, setDeferHeight, setEnabled, setHeight, setHeight, setHideMode, setId, setItemId, setPagePosition, setPixelSize, setPosition, setShadow, setSize, setStateful, setStateId, setTabIndex, setToolTip, setToolTipConfig, setVisible, setWidth, setWidth, show, sync, syncSize, unmask
 
Methods inherited from class com.google.gwt.user.client.ui.Widget
addAttachHandler, addBitlessDomHandler, addDomHandler, addHandler, asWidget, asWidgetOrNull, getLayoutData, getParent, isAttached, removeFromParent, setLayoutData, sinkEvents
 
Methods inherited from class com.google.gwt.user.client.ui.UIObject
addStyleDependentName, addStyleName, ensureDebugId, ensureDebugId, getAbsoluteLeft, getAbsoluteTop, getOffsetHeight, getOffsetWidth, getStyleName, getStylePrimaryName, getTitle, isVisible, removeStyleDependentName, removeStyleName, setStyleDependentName, setStyleName, setStyleName, setStylePrimaryName, setTitle, setVisible, sinkBitlessEvent, toString, unsinkEvents
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface com.google.gwt.event.shared.HasHandlers
fireEvent
 

Constructor Detail

Grid

@UiConstructor
public Grid(ListStore<M> store,
                          ColumnModel<M> cm,
                          GridView<M> view)
Creates a new grid with the given data store and column model.

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

Grid

public Grid(ListStore<M> store,
            ColumnModel<M> cm)
Creates a new grid with the given data store and column model.

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

addBodyScrollHandler

public HandlerRegistration addBodyScrollHandler(BodyScrollEvent.BodyScrollHandler handler)
Specified by:
addBodyScrollHandler in interface BodyScrollEvent.HasBodyScrollHandlers

addCellClickHandler

public HandlerRegistration addCellClickHandler(CellClickEvent.CellClickHandler handler)
Specified by:
addCellClickHandler in interface CellClickEvent.HasCellClickHandlers

addCellDoubleClickHandler

public HandlerRegistration addCellDoubleClickHandler(CellDoubleClickEvent.CellDoubleClickHandler handler)
Specified by:
addCellDoubleClickHandler in interface CellDoubleClickEvent.HasCellDoubleClickHandlers

addCellMouseDownHandler

public HandlerRegistration addCellMouseDownHandler(CellMouseDownEvent.CellMouseDownHandler handler)
Specified by:
addCellMouseDownHandler in interface CellMouseDownEvent.HasCellMouseDownHandlers

addHeaderClickHandler

public HandlerRegistration addHeaderClickHandler(HeaderClickEvent.HeaderClickHandler handler)
Specified by:
addHeaderClickHandler in interface HeaderClickEvent.HasHeaderClickHandlers

addHeaderContextMenuHandler

public HandlerRegistration addHeaderContextMenuHandler(HeaderContextMenuEvent.HeaderContextMenuHandler handler)
Specified by:
addHeaderContextMenuHandler in interface HeaderContextMenuEvent.HasHeaderContextMenuHandlers

addHeaderDoubleClickHandler

public HandlerRegistration addHeaderDoubleClickHandler(HeaderDoubleClickEvent.HeaderDoubleClickHandler handler)
Specified by:
addHeaderDoubleClickHandler in interface HeaderDoubleClickEvent.HasHeaderDoubleClickHandlers

addHeaderMouseDownHandler

public HandlerRegistration addHeaderMouseDownHandler(HeaderMouseDownEvent.HeaderMouseDownHandler handler)
Specified by:
addHeaderMouseDownHandler in interface HeaderMouseDownEvent.HasHeaderMouseDownHandlers

addReconfigureHandler

public HandlerRegistration addReconfigureHandler(ReconfigureEvent.ReconfigureHandler handler)
Specified by:
addReconfigureHandler in interface ReconfigureEvent.HasReconfigureHandlers

addRefreshHandler

public HandlerRegistration addRefreshHandler(RefreshEvent.RefreshHandler handler)
Description copied from interface: RefreshEvent.HasRefreshHandlers
Adds a RefreshEvent.RefreshHandler handler for RefreshEvent events.

Specified by:
addRefreshHandler in interface RefreshEvent.HasRefreshHandlers
Parameters:
handler - the handler
Returns:
the registration for the event

addRowClickHandler

public HandlerRegistration addRowClickHandler(RowClickEvent.RowClickHandler handler)
Specified by:
addRowClickHandler in interface RowClickEvent.HasRowClickHandlers

addRowDoubleClickHandler

public HandlerRegistration addRowDoubleClickHandler(RowDoubleClickEvent.RowDoubleClickHandler handler)
Specified by:
addRowDoubleClickHandler in interface RowDoubleClickEvent.HasRowDoubleClickHandlers

addRowMouseDownHandler

public HandlerRegistration addRowMouseDownHandler(RowMouseDownEvent.RowMouseDownHandler handler)
Specified by:
addRowMouseDownHandler in interface RowMouseDownEvent.HasRowMouseDownHandlers

addSortChangeHandler

public HandlerRegistration addSortChangeHandler(SortChangeEvent.SortChangeHandler handler)
Specified by:
addSortChangeHandler in interface SortChangeEvent.HasSortChangeHandlers

addViewReadyHandler

public HandlerRegistration addViewReadyHandler(ViewReadyEvent.ViewReadyHandler handler)
Specified by:
addViewReadyHandler in interface ViewReadyEvent.HasViewReadyHandlers

getColumnModel

public ColumnModel<M> 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

getLoader

public ListLoader<?,?> getLoader()
Returns the loader.

Returns:
the loader

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<M> getView()
Returns the grid's view.

Returns:
the grid view

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

isViewReady

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

Returns:
the view ready state

onBrowserEvent

public void onBrowserEvent(Event ce)
Specified by:
onBrowserEvent in interface EventListener
Overrides:
onBrowserEvent in class Component

reconfigure

public void reconfigure(ListStore<M> store,
                        ColumnModel<M> 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

setAllowTextSelection

public void setAllowTextSelection(boolean enable)
Description copied from class: Component
Enables and disables text selection for the widget.

Overrides:
setAllowTextSelection in class Component
Parameters:
enable - true to enable, false to disable

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.

setLoader

public void setLoader(ListLoader<?,?> loader)
Sets the loader.

Parameters:
loader - the loader

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

setView

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

Parameters:
view - the view

walkCells

public Grid.GridCell walkCells(int row,
                               int col,
                               int step,
                               Grid.Callback callback)
Navigate in the requested direction to the next selectable cell, given the row, column and step.

Parameters:
row - the starting row index
col - the starting column index
step - the step size and direction
callback - a callback that determines whether the given cell is selectable
Returns:
the next cell or null if no cell matches the criteria


Copyright © 2012. All Rights Reserved.