
M - the model typepublic 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
A Grid provides support for displaying and editing two-dimensional
tables of cells. The grid gets its data from a ListStore and its
column definitions from a ColumnModel. Each model in the store is
rendered as a row in the grid. The fields in the model provide the data for
each column in the row. Any updates to the store are automatically pushed to
the grid. This includes inserting, removing, sorting and filtering.
In GXT version 3, ModelKeyProviders and ValueProviders
provide the interface between your data model and the list store and
ColumnConfig classes. This enables a grid to work with data of any
object type.
You can provide your own implementation of these interfaces, or you can use a
Sencha supplied generator to create them for you automatically. A generator
runs at compile time to create a Java class that is compiled to JavaScript.
The Sencha supplied generator can create classes for interfaces that extend
the PropertyAccess interface. The generator transparently creates the
class at compile time and the GWT#create(Class) method returns an
instance of that class at run time. The generated class is managed by GWT and
GXT and you generally do not need to worry about what the class is called,
where it is located, or other similar details.
Each grid has a GridView. The grid view provides many options for
customizing the grid's appearance (e.g. striping, mouse-over tracking, empty
text). To set these options, get the current grid view using
getView() and then set the desired option on the grid view.
To customize the appearance of a column in a grid, provide a cell
implementation using ColumnConfig#setCell(Cell).
Grids support several ways to manage column widths:
GridView.setAutoExpandColumn(ColumnConfig).GridView.setAutoFill(boolean) or
GridView.setForceFit(boolean) to enable this feature:
ColumnConfig.setFixed(boolean).The following code snippet illustrates the creation of a simple grid with local data for test purposes. For more practical examples that show how to load data from remote sources, see the Json Grid, Live Grid, Paging Grid, RequestFactory Grid and Xml Grid examples in the online Explorer demo.
// Create an instance of the generated key and value providers for the Data class
DataProperties dp = GWT.create(DataProperties.class);
// Create the configurations for each column in the grid
List<ColumnConfig<Data, ?>> ccs = new LinkedList<ColumnConfig<Data, ?>>();
ccs.add(new ColumnConfig<Data, String>(dp.name(), 200, "Name"));
ccs.add(new ColumnConfig<Data, String>(dp.value(), 200, "Value"));
ColumnModel<Data> cm = new ColumnModel<Test.Data>(ccs);
// Create the store that the contains the data to display in the grid
ListStore<Data> s = new ListStore<Test.Data>(dp.key());
s.add(new Data("name1", "value1"));
s.add(new Data("name2", "value2"));
s.add(new Data("name3", "value3"));
s.add(new Data("name4", "value4"));
// Create the grid using the store and column configurations
Grid<Data> g = new Grid<Data>(s, cm);
// Add the grid to a container
RootPanel.get().add(g);
To use the Sencha supplied generator to create model key providers and value providers, extend the PropertyAccess interface, parameterized with the type of data you want to access (as shown below) and invoke the GWT.create method on its class member (as shown in the code snippet above). This creates an instance of the class that can be used to initialize the column configuration and list store. In the following code snippet we define a new interface called DataProperties that extends the PropertyAccess interface and is parameterized with Data, a Plain Old Java Object (POJO).
public interface DataProperties extends PropertyAccess<Data> {
@Path("name")
ModelKeyProvider<Data> key();
ValueProvider<Data, String> name();
ValueProvider<Data, String> value();
}
public class Data {
protected String name;
protected String value;
public Data(String name, String value) {
super();
this.name = name;
this.value = value;
}
public String getName() {
return name;
}
public String getValue() {
return value;
}
public void setName(String name) {
this.name = name;
}
public void setValue(String value) {
this.value = value;
}
}
To enable drag and drop for a grid, add the following:
new GridDragSource<Data>(g);
GridDropTarget<Data> dt = new GridDropTarget<Data>(g);
dt.setFeedback(Feedback.BOTH);
To add reordering support to the drag and drop, include:
dt.setAllowSelfAsSource(true);
| Modifier and Type | Class and Description |
|---|---|
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.
|
| Modifier and Type | Field and Description |
|---|---|
protected ColumnModel<M> |
cm
The current column model for this grid.
|
protected boolean |
enableColumnReorder |
protected boolean |
enableColumnResize |
protected boolean |
hideHeaders |
protected int |
lazyRowRender |
protected ListLoader<?,?> |
loader |
protected HandlerRegistration |
loaderRegistration |
protected LoaderHandler<ListLoadConfig,ListLoadResult<?>> |
loadHandler |
protected boolean |
loadMask |
protected GridSelectionModel<M> |
sm
The current selection model for this grid.
|
protected ListStore<M> |
store
The current store for this grid.
|
protected GridView<M> |
view
The current view for this grid.
|
protected boolean |
viewReady
The current view for this grid.
|
adjustSize, allowTextSelection, cacheSizes, contextMenu, contextMenuGestureRecognizer, dataMap, deferHeight, disableContextMenu, disabled, disabledStyle, disableEvents, ensureVisibilityOnSizing, focusManagerSupport, gestureRecognizers, height, hidden, hideMode, itemId, lastSize, layer, left, mask, maskMessage, monitorWindowResize, overElements, pageX, pageY, resizeHandler, shadow, shadowPosition, shim, stateful, stateId, tabIndex, toolTip, toolTipConfig, top, width, windowResizeDelay, windowResizeTask| Modifier | Constructor and Description |
|---|---|
protected |
Grid()
Creates a grid to be initialized by derived classes.
|
|
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.
|
| Modifier and Type | Method and Description |
|---|---|
HandlerRegistration |
addBodyScrollHandler(BodyScrollEvent.BodyScrollHandler handler) |
HandlerRegistration |
addCellClickHandler(CellClickEvent.CellClickHandler handler) |
HandlerRegistration |
addCellDoubleClickHandler(CellDoubleClickEvent.CellDoubleClickHandler handler) |
HandlerRegistration |
addCellMouseDownHandler(CellMouseDownEvent.CellMouseDownHandler handler) |
HandlerRegistration |
addCellMouseUpHandler(CellMouseUpEvent.CellMouseUpHandler handler)
Add cell mouse up handler.
|
HandlerRegistration |
addCellTapHandler(CellTapEvent.CellTapHandler handler)
Add a cell tap 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 |
addRowMouseUpHandler(RowMouseUpEvent.RowMouseUpHandler handler)
Add row mouse up handler.
|
HandlerRegistration |
addRowTapHandler(RowTapEvent.RowTapHandler handler)
Add a row tap handler.
|
HandlerRegistration |
addSortChangeHandler(SortChangeEvent.SortChangeHandler handler) |
HandlerRegistration |
addViewReadyHandler(ViewReadyEvent.ViewReadyHandler handler) |
protected void |
afterRenderView()
Invoked after the view element is first attached, performs the final steps
before the grid is completely initialized.
|
protected boolean |
cellConsumesEventType(<any> cell,
String eventType)
Returns true if the given cell consumes the given event.
|
protected void |
doAttachChildren() |
protected void |
doDetachChildren() |
protected <N> <any> |
fireEventToCell(Event event,
String eventType,
Element cellParent,
M m,
Context context,
ColumnConfig<M,N> column)
Fires an event to the cell specified by the given record data model and
column.
|
void |
focus()
Try to focus this widget.
|
ColumnModel<M> |
getColumnModel()
Returns the column model.
|
int |
getLazyRowRender()
Returns the time in ms after the rows get rendered.
|
ListLoader<?,?> |
getLoader()
Returns the loader.
|
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.
|
protected <any> |
handleEventForCell(Event event)
Inspects the given event and fires it to a cell if possible.
|
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.
|
protected void |
notifyHide() |
protected void |
notifyShow() |
protected void |
onAfterFirstAttach()
Called immediately after the first time the widget becomes attached to the browser's document only the first time.
|
protected void |
onAfterRenderView()
Invoked after the view has been rendered, may be overridden to perform any
activities that require a rendered view.
|
protected void |
onAttach() |
void |
onBrowserEvent(Event event) |
protected void |
onClick(Event e)
Handles the browser click event.
|
protected void |
onDisable() |
protected void |
onDoubleClick(Event e)
Handles the browser double click event.
|
protected void |
onEnable() |
protected void |
onFocus(Event event) |
protected void |
onGestureCancel(List<TouchData> touches) |
protected void |
onGestureEnd(List<TouchData> touches) |
protected void |
onGestureLongPress(TouchData touchData) |
protected void |
onGestureStart(TouchData startedTouch) |
protected void |
onGestureTap(TouchData touchData) |
protected void |
onLoaderBeforeLoad()
Invoked before the loader loads new data, displays the Loading...
|
protected void |
onLoaderLoadException()
Invoked if the loader encounters an exception, cancels the Loading...
|
protected void |
onLoadLoader()
Invoked after the loader loads new data, cancels the Loading...
|
protected void |
onMouseDown(Event event)
Handles the browser mouse down event.
|
protected void |
onMouseUp(Event event)
Handles the browser mouse up event.
|
protected void |
onResize(int width,
int height)
Called after the widget 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<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 |
setSelectionModel(GridSelectionModel<M> sm)
Sets the grid selection model.
|
void |
setView(GridView<M> view)
Sets the grid's view.
|
protected void |
sinkCellEvents()
Sinks all the events consumed by the cells in the column configs.
|
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.
|
addBeforeHideHandler, addBeforeShowContextMenuHandler, addBeforeShowHandler, addBlurHandler, addDisableHandler, addEnableHandler, addFocusHandler, addGestureRecognizer, addHideHandler, addMoveHandler, addResizeHandler, addShowContextMenuHandler, addShowHandler, addStyleDependentName, addStyleOnOver, adjustPosition, adjustSize, applyState, assertAfterRender, assertPreRender, blur, clearSizeCache, disable, disableContextMenu, disableEvents, enable, enableEvents, fireCancellableEvent, fireEvent, getData, getElement, getFocusEl, getFocusSupport, getGestureRecognizer, getGestureRecognizerCount, getHideMode, getId, getItemId, getOffsetHeight, getOffsetWidth, getPositionEl, getShadow, getShadowPosition, getStateId, getTabIndex, getToolTip, hide, hideShadow, hideToolTip, isAdjustSize, isAllowTextSelection, isAutoHeight, isAutoWidth, isDeferHeight, isEnabled, isMonitorWindowResize, isRendered, isStateful, isVisible, isVisible, makeVisible, mask, mask, onBlur, onDetach, onHide, onHideContextMenu, onLoad, onPosition, onRightClick, onShow, onShowContextMenu, onTouch, onUnload, onWindowResize, removeGestureRecognizer, removeStyleDependentName, removeStyleOnOver, removeToolTip, restoreVisible, setAdjustSize, setBorders, setBounds, setBounds, setContextMenu, setData, setDeferHeight, setEnabled, setHeight, setHeight, setHideMode, setId, setItemId, setMonitorWindowResize, setPagePosition, setPixelSize, setPosition, setShadow, setShadowPosition, setSize, setStateful, setStateId, setStyleDependentName, setTabIndex, setToolTip, setToolTipConfig, setVisible, setWidth, setWidth, show, sync, syncSize, unmaskprotected ColumnModel<M> cm
protected GridSelectionModel<M> sm
protected ListStore<M> store
protected GridView<M> view
protected boolean viewReady
protected ListLoader<?,?> loader
protected boolean enableColumnReorder
protected boolean enableColumnResize
protected boolean hideHeaders
protected int lazyRowRender
protected HandlerRegistration loaderRegistration
protected LoaderHandler<ListLoadConfig,ListLoadResult<?>> loadHandler
protected boolean loadMask
public Grid(ListStore<M> store, ColumnModel<M> cm)
store - the data storecm - the column modelpublic Grid(ListStore<M> store, ColumnModel<M> cm, GridView<M> view)
store - the data storecm - the column modelview - the grid viewprotected Grid()
public HandlerRegistration addBodyScrollHandler(BodyScrollEvent.BodyScrollHandler handler)
addBodyScrollHandler in interface BodyScrollEvent.HasBodyScrollHandlerspublic HandlerRegistration addCellClickHandler(CellClickEvent.CellClickHandler handler)
addCellClickHandler in interface CellClickEvent.HasCellClickHandlerspublic HandlerRegistration addCellDoubleClickHandler(CellDoubleClickEvent.CellDoubleClickHandler handler)
addCellDoubleClickHandler in interface CellDoubleClickEvent.HasCellDoubleClickHandlerspublic HandlerRegistration addCellMouseDownHandler(CellMouseDownEvent.CellMouseDownHandler handler)
addCellMouseDownHandler in interface CellMouseDownEvent.HasCellMouseDownHandlerspublic HandlerRegistration addHeaderClickHandler(HeaderClickEvent.HeaderClickHandler handler)
addHeaderClickHandler in interface HeaderClickEvent.HasHeaderClickHandlerspublic HandlerRegistration addHeaderContextMenuHandler(HeaderContextMenuEvent.HeaderContextMenuHandler handler)
addHeaderContextMenuHandler in interface HeaderContextMenuEvent.HasHeaderContextMenuHandlerspublic HandlerRegistration addHeaderDoubleClickHandler(HeaderDoubleClickEvent.HeaderDoubleClickHandler handler)
addHeaderDoubleClickHandler in interface HeaderDoubleClickEvent.HasHeaderDoubleClickHandlerspublic HandlerRegistration addHeaderMouseDownHandler(HeaderMouseDownEvent.HeaderMouseDownHandler handler)
addHeaderMouseDownHandler in interface HeaderMouseDownEvent.HasHeaderMouseDownHandlerspublic HandlerRegistration addReconfigureHandler(ReconfigureEvent.ReconfigureHandler handler)
addReconfigureHandler in interface ReconfigureEvent.HasReconfigureHandlerspublic HandlerRegistration addRefreshHandler(RefreshEvent.RefreshHandler handler)
RefreshEvent.HasRefreshHandlersRefreshEvent.RefreshHandler handler for
RefreshEvent events.addRefreshHandler in interface RefreshEvent.HasRefreshHandlershandler - the handlerpublic HandlerRegistration addRowClickHandler(RowClickEvent.RowClickHandler handler)
addRowClickHandler in interface RowClickEvent.HasRowClickHandlerspublic HandlerRegistration addRowDoubleClickHandler(RowDoubleClickEvent.RowDoubleClickHandler handler)
addRowDoubleClickHandler in interface RowDoubleClickEvent.HasRowDoubleClickHandlerspublic HandlerRegistration addRowMouseDownHandler(RowMouseDownEvent.RowMouseDownHandler handler)
addRowMouseDownHandler in interface RowMouseDownEvent.HasRowMouseDownHandlerspublic HandlerRegistration addRowMouseUpHandler(RowMouseUpEvent.RowMouseUpHandler handler)
handler - row mouse up handlerpublic HandlerRegistration addCellMouseUpHandler(CellMouseUpEvent.CellMouseUpHandler handler)
handler - row mouse up handlerpublic HandlerRegistration addRowTapHandler(RowTapEvent.RowTapHandler handler)
handler - row mouse up handlerpublic HandlerRegistration addCellTapHandler(CellTapEvent.CellTapHandler handler)
handler - row mouse up handlerpublic HandlerRegistration addSortChangeHandler(SortChangeEvent.SortChangeHandler handler)
addSortChangeHandler in interface SortChangeEvent.HasSortChangeHandlerspublic HandlerRegistration addViewReadyHandler(ViewReadyEvent.ViewReadyHandler handler)
addViewReadyHandler in interface ViewReadyEvent.HasViewReadyHandlerspublic void focus()
Componentpublic ColumnModel<M> getColumnModel()
public int getLazyRowRender()
public ListLoader<?,?> getLoader()
public GridSelectionModel<M> getSelectionModel()
public boolean isColumnReordering()
public boolean isColumnResize()
public boolean isHideHeaders()
public boolean isLoadMask()
public boolean isViewReady()
public void onBrowserEvent(Event event)
onBrowserEvent in class Componentpublic void reconfigure(ListStore<M> store, ColumnModel<M> cm)
store - the new storecm - the new column modelpublic void setAllowTextSelection(boolean enable)
ComponentsetAllowTextSelection in class Componentenable - true to enable, false to disablepublic void setColumnReordering(boolean enableColumnReorder)
enableColumnReorder - true to enablepublic void setColumnResize(boolean enableColumnResize)
enableColumnResize - true to allow column resizingpublic void setHideHeaders(boolean hideHeaders)
hideHeaders - true to hide the headerpublic void setLazyRowRender(int lazyRowRender)
lazyRowRender - the time in ms after the rows get rendered.public void setLoader(ListLoader<?,?> loader)
loader - the loaderpublic void setLoadMask(boolean loadMask)
loadMask - true to show a maskpublic void setSelectionModel(GridSelectionModel<M> sm)
sm - the selection modelpublic void setView(GridView<M> view)
view - the view to use for this gridpublic Grid.GridCell walkCells(int row, int col, int step, Grid.Callback callback)
row - the starting row indexcol - the starting column indexstep - the step size and directioncallback - a callback that determines whether the given cell is
selectableprotected void afterRenderView()
protected boolean cellConsumesEventType(<any> cell,
String eventType)
cell - the cell to inspecteventType - the eventprotected void doAttachChildren()
protected void doDetachChildren()
protected <N> <any> fireEventToCell(Event event,
String eventType,
Element cellParent,
M m,
Context context,
ColumnConfig<M,N> column)
event - the event to fireeventType - the type of eventcellParent - the containing parent elementm - the record data model containing the cellcontext - the context of the cell (row, column and key)column - the column containing the cellprotected <any> handleEventForCell(Event event)
event - the event to handleprotected void notifyHide()
notifyHide in class Componentprotected void notifyShow()
notifyShow in class Componentprotected void onAfterFirstAttach()
ComponentonAfterFirstAttach in class Componentprotected void onAfterRenderView()
protected void onClick(Event e)
e - the click eventprotected void onDoubleClick(Event e)
e - the double click eventprotected void onGestureStart(TouchData startedTouch)
protected void onGestureTap(TouchData touchData)
protected void onGestureLongPress(TouchData touchData)
protected void onLoaderBeforeLoad()
protected void onLoaderLoadException()
protected void onLoadLoader()
protected void onMouseDown(Event event)
event - the mouse down eventprotected void onMouseUp(Event event)
event - the mouse up eventprotected void onResize(int width,
int height)
Componentprotected void sinkCellEvents()
Copyright © 2020. All rights reserved.