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
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, ModelKeyProvider
s and ValueProvider
s
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)
.// 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 { @Path("name") ModelKeyProvider key(); ValueProvider<Data, String> name(); ValueProvider<Data, String> value(); } public class Data { private String name; private 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(g); GridDropTarget dt = new GridDropTarget(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.
|
UIObject.DebugIdImpl, UIObject.DebugIdImplEnabled
DEBUG_ID_PREFIX
Constructor and Description |
---|
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 |
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) |
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.
|
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 |
setSelectionModel(GridSelectionModel<M> sm)
Sets the grid selection model.
|
void |
setView(GridView<M> view)
Sets the grid's view.
|
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, addHideHandler, addMoveHandler, addResizeHandler, addShowContextMenuHandler, addShowHandler, addStyleOnOver, clearSizeCache, disable, disableEvents, enable, enableEvents, fireEvent, getData, getElement, getFocusSupport, getHideMode, getId, getItemId, getOffsetHeight, getOffsetWidth, getShadow, getShadowPosition, getStateId, getTabIndex, 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, setShadowPosition, setSize, setStateful, setStateId, setTabIndex, setToolTip, setToolTip, setToolTipConfig, setVisible, setWidth, setWidth, show, sync, syncSize, unmask
addAttachHandler, addBitlessDomHandler, addDomHandler, addHandler, asWidget, asWidgetOrNull, getLayoutData, getParent, isAttached, removeFromParent, setLayoutData, sinkEvents, unsinkEvents
addStyleDependentName, addStyleName, ensureDebugId, ensureDebugId, getAbsoluteLeft, getAbsoluteTop, getOffsetHeight, getOffsetWidth, getStyleName, getStylePrimaryName, getTitle, isVisible, removeStyleDependentName, removeStyleName, setStyleDependentName, setStyleName, setStyleName, setStylePrimaryName, setTitle, setVisible, sinkBitlessEvent, toString
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
fireEvent
public Grid(ListStore<M> store, ColumnModel<M> cm)
store
- the data storecm
- the column model@UiConstructor public Grid(ListStore<M> store, ColumnModel<M> cm, GridView<M> view)
store
- the data storecm
- the column modelpublic HandlerRegistration addBodyScrollHandler(BodyScrollEvent.BodyScrollHandler handler)
addBodyScrollHandler
in interface BodyScrollEvent.HasBodyScrollHandlers
public HandlerRegistration addCellClickHandler(CellClickEvent.CellClickHandler handler)
addCellClickHandler
in interface CellClickEvent.HasCellClickHandlers
public HandlerRegistration addCellDoubleClickHandler(CellDoubleClickEvent.CellDoubleClickHandler handler)
addCellDoubleClickHandler
in interface CellDoubleClickEvent.HasCellDoubleClickHandlers
public HandlerRegistration addCellMouseDownHandler(CellMouseDownEvent.CellMouseDownHandler handler)
addCellMouseDownHandler
in interface CellMouseDownEvent.HasCellMouseDownHandlers
public HandlerRegistration addHeaderClickHandler(HeaderClickEvent.HeaderClickHandler handler)
addHeaderClickHandler
in interface HeaderClickEvent.HasHeaderClickHandlers
public HandlerRegistration addHeaderContextMenuHandler(HeaderContextMenuEvent.HeaderContextMenuHandler handler)
addHeaderContextMenuHandler
in interface HeaderContextMenuEvent.HasHeaderContextMenuHandlers
public HandlerRegistration addHeaderDoubleClickHandler(HeaderDoubleClickEvent.HeaderDoubleClickHandler handler)
addHeaderDoubleClickHandler
in interface HeaderDoubleClickEvent.HasHeaderDoubleClickHandlers
public HandlerRegistration addHeaderMouseDownHandler(HeaderMouseDownEvent.HeaderMouseDownHandler handler)
addHeaderMouseDownHandler
in interface HeaderMouseDownEvent.HasHeaderMouseDownHandlers
public HandlerRegistration addReconfigureHandler(ReconfigureEvent.ReconfigureHandler handler)
addReconfigureHandler
in interface ReconfigureEvent.HasReconfigureHandlers
public HandlerRegistration addRefreshHandler(RefreshEvent.RefreshHandler handler)
RefreshEvent.HasRefreshHandlers
RefreshEvent.RefreshHandler
handler for
RefreshEvent
events.addRefreshHandler
in interface RefreshEvent.HasRefreshHandlers
handler
- the handlerpublic HandlerRegistration addRowClickHandler(RowClickEvent.RowClickHandler handler)
addRowClickHandler
in interface RowClickEvent.HasRowClickHandlers
public HandlerRegistration addRowDoubleClickHandler(RowDoubleClickEvent.RowDoubleClickHandler handler)
addRowDoubleClickHandler
in interface RowDoubleClickEvent.HasRowDoubleClickHandlers
public HandlerRegistration addRowMouseDownHandler(RowMouseDownEvent.RowMouseDownHandler handler)
addRowMouseDownHandler
in interface RowMouseDownEvent.HasRowMouseDownHandlers
public HandlerRegistration addSortChangeHandler(SortChangeEvent.SortChangeHandler handler)
addSortChangeHandler
in interface SortChangeEvent.HasSortChangeHandlers
public HandlerRegistration addViewReadyHandler(ViewReadyEvent.ViewReadyHandler handler)
addViewReadyHandler
in interface ViewReadyEvent.HasViewReadyHandlers
public void focus()
Component
public 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 ce)
onBrowserEvent
in interface EventListener
onBrowserEvent
in class Component
public void reconfigure(ListStore<M> store, ColumnModel<M> cm)
store
- the new storecm
- the new column modelpublic void setAllowTextSelection(boolean enable)
Component
setAllowTextSelection
in class Component
enable
- 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
selectablenull
if no cell matches the criteriaCopyright © 2015. All rights reserved.