Class DataTable<T,S>
- java.lang.Object
-
- org.apache.wicket.Component
-
- org.apache.wicket.MarkupContainer
-
- org.apache.wicket.markup.html.WebMarkupContainer
-
- org.apache.wicket.markup.html.panel.Panel
-
- org.apache.wicket.extensions.markup.html.repeater.data.table.DataTable<T,S>
-
- Type Parameters:
T
- The model object typeS
- the type of the sorting parameter
- All Implemented Interfaces:
Serializable
,Iterable<Component>
,IEventSink
,IEventSource
,IFeedbackContributor
,IConverterLocator
,IMetadataContext<Serializable,Component>
,IQueueRegion
,IHeaderContributor
,IPageable
,IPageableItems
,IRequestableComponent
,IHierarchical<Component>
,IClusterable
- Direct Known Subclasses:
AjaxFallbackDefaultDataTable
,DefaultDataTable
public class DataTable<T,S> extends Panel implements IPageableItems
A data table builds on data grid view to introduce toolbars. Toolbars can be used to display sortable column headers, paging information, filter controls, and other information.Data table also provides its own markup for an html table so the developer does not need to provide it himself. This makes it very simple to add a datatable to the markup, however, some flexibility.
Example
<table wicket:id="datatable"></table>
And the related Java code: ( the first column will be sortable because its sort property is specified, the second column will not )// Application specific POJO to view/edit public class MyEntity { private String firstName; private String lastName; // getters and setters } public class MyEntityProvider implements IDataProvider<MyEntity> { ... } List<IColumn<MyEntity, String>> columns = new ArrayList<>(); columns.add(new PropertyColumn<MyEntity, String>(new Model<String>("First Name"), "firstName", "firstName")); columns.add(new PropertyColumn<MyEntity, String>(new Model<String>("Last Name"), "lastName")); DataTable<MyEntity,String> table = new DataTable<>("datatable", columns, new MyEntityProvider(), 10); table.addBottomToolbar(new NavigationToolbar(table)); table.addTopToolbar(new HeadersToolbar(table, null)); add(table);
- Author:
- Igor Vaynberg (ivaynberg)
- See Also:
DefaultDataTable
, Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
DataTable.Caption
A caption for the table.
-
Field Summary
-
Fields inherited from class org.apache.wicket.Component
ENABLE, FLAG_INITIALIZED, FLAG_RESERVED1, FLAG_RESERVED2, FLAG_RESERVED3, FLAG_RESERVED4, FLAG_RESERVED5, FLAG_RESERVED8, PARENT_PATH, PATH_SEPARATOR, RENDER, RFLAG_CONTAINER_DEQUEING, RFLAG_CONTAINER_HAS_REMOVALS
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addBottomToolbar(AbstractToolbar toolbar)
Adds a toolbar to the datatable that will be displayed after the datavoid
addTopToolbar(AbstractToolbar toolbar)
Adds a toolbar to the datatable that will be displayed before the dataWebMarkupContainer
getBody()
WebMarkupContainer
getBottomToolbars()
DataTable.Caption
getCaption()
protected IModel<String>
getCaptionModel()
Returns the model for table's caption.ColGroup
getColGroup()
List<? extends IColumn<T,S>>
getColumns()
long
getCurrentPage()
IDataProvider<T>
getDataProvider()
long
getItemCount()
Gets the total number of items this object has.long
getItemsPerPage()
maximum number of visible items per pagelong
getPageCount()
Gets the total number of pages this pageable object has.long
getRowCount()
WebMarkupContainer
getTopToolbars()
protected WebMarkupContainer
newBodyContainer(String id)
Create the MarkupContainer for the tag.protected Item<IColumn<T,S>>
newCellItem(String id, int index, IModel<IColumn<T,S>> model)
Factory method for Item container that represents a cell in the underlying DataGridViewprotected DataGridView<T>
newDataGridView(String id, List<? extends IColumn<T,S>> columns, IDataProvider<T> dataProvider)
Factory method for the DataGridViewprotected Item<T>
newRowItem(String id, int index, IModel<T> model)
Factory method for Item container that represents a row in the underlying DataGridViewprotected void
onComponentTag(ComponentTag tag)
Processes the component tag.protected void
onDetach()
Called to allow a component to detach resources after use.protected void
onPageChanged()
Event listener for page-changed eventvoid
setCurrentPage(long page)
Sets the a page that should be rendered (page number is zero-based)DataTable<T,S>
setItemReuseStrategy(IItemReuseStrategy strategy)
Sets the item reuse strategy.void
setItemsPerPage(long items)
Sets the number of items to be displayed per pagevoid
setTableBodyCss(String cssStyle)
Set the 'class' attribute for the tbody tag.-
Methods inherited from class org.apache.wicket.markup.html.panel.Panel
getRegionMarkup, newMarkupSourcingStrategy
-
Methods inherited from class org.apache.wicket.markup.html.WebMarkupContainer
getWebApplication, getWebPage, getWebRequest, getWebResponse, getWebSession
-
Methods inherited from class org.apache.wicket.MarkupContainer
add, addDequeuedComponent, addOrReplace, autoAdd, canDequeueTag, contains, dequeue, dequeue, dequeuePreamble, findChildComponent, findComponentToDequeue, get, getAssociatedMarkup, getAssociatedMarkupStream, getMarkup, getMarkupType, internalAdd, internalInitialize, iterator, iterator, newDequeueContext, onComponentTagBody, onInitialize, onRender, queue, remove, remove, removeAll, renderAll, renderAssociatedMarkup, renderAssociatedMarkup, renderNext, replace, setDefaultModel, size, stream, streamChildren, toString, toString, visitChildren, visitChildren
-
Methods inherited from class org.apache.wicket.Component
add, addStateChange, beforeRender, canCallListener, canCallListenerAfterExpiry, checkComponentTag, checkComponentTagAttribute, checkHierarchyChange, clearOriginalDestination, configure, continueToOriginalDestination, createConverter, debug, detach, detachModel, detachModels, determineVisibility, error, exceptionMessage, fatal, findMarkupStream, findPage, findParent, findParentWithAssociatedMarkup, getAjaxRegionMarkupId, getApplication, getBehaviorById, getBehaviorId, getBehaviors, getBehaviors, getClassRelativePath, getConverter, getDefaultModel, getDefaultModelObject, getDefaultModelObjectAsString, getDefaultModelObjectAsString, getEscapeModelStrings, getFeedbackMessages, getFlag, getId, getInnermostModel, getInnermostModel, getLocale, getLocalizer, getMarkup, getMarkupAttributes, getMarkupId, getMarkupId, getMarkupIdFromMarkup, getMarkupIdImpl, getMarkupSourcingStrategy, getMarkupTag, getMetaData, getModelComparator, getOutputMarkupId, getOutputMarkupPlaceholderTag, getPage, getPageRelativePath, getParent, getPath, getRenderBodyOnly, getRequest, getRequestCycle, getRequestFlag, getResponse, getSession, getSizeInBytes, getStatelessHint, getString, getString, getString, getStyle, getVariation, hasBeenRendered, hasErrorMessage, hasFeedbackMessage, info, initModel, internalOnModelChanged, internalRenderComponent, internalRenderHead, isActionAuthorized, isAuto, isBehaviorAccepted, isEnableAllowed, isEnabled, isEnabledInHierarchy, isIgnoreAttributeModifier, isInitialized, isRenderAllowed, isRendering, isStateless, isVersioned, isVisibilityAllowed, isVisible, isVisibleInHierarchy, markRendering, modelChanged, modelChanging, onAfterRender, onBeforeRender, onConfigure, onEvent, onModelChanged, onModelChanging, onReAdd, onRemove, redirectToInterceptPage, remove, remove, render, renderComponentTag, rendered, renderHead, renderPart, renderPlaceholderTag, replaceComponentTagBody, replaceWith, sameInnermostModel, sameInnermostModel, send, setAuto, setDefaultModelObject, setEnabled, setEscapeModelStrings, setFlag, setIgnoreAttributeModifier, setMarkup, setMarkupId, setMarkupIdImpl, setMetaData, setOutputMarkupId, setOutputMarkupPlaceholderTag, setParent, setRenderBodyOnly, setResponsePage, setResponsePage, setResponsePage, setVersioned, setVisibilityAllowed, setVisible, success, urlFor, urlFor, urlFor, urlForListener, urlForListener, visitParents, visitParents, warn, wrap
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.apache.wicket.IQueueRegion
dequeue, newDequeueContext
-
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
-
-
-
Method Detail
-
newDataGridView
protected DataGridView<T> newDataGridView(String id, List<? extends IColumn<T,S>> columns, IDataProvider<T> dataProvider)
Factory method for the DataGridView- Parameters:
id
- The component idcolumns
- list of IColumn objectsdataProvider
- imodel for data provider- Returns:
- the data grid view
-
getCaptionModel
protected IModel<String> getCaptionModel()
Returns the model for table's caption. The caption wont be rendered if the model has empty value.- Returns:
- the model for table's caption
-
getColGroup
public final ColGroup getColGroup()
-
newBodyContainer
protected WebMarkupContainer newBodyContainer(String id)
Create the MarkupContainer for the tag. Developers may subclass it to provide their own (modified) implementation.- Parameters:
id
-- Returns:
- A new markup container
-
setTableBodyCss
public final void setTableBodyCss(String cssStyle)
Set the 'class' attribute for the tbody tag.- Parameters:
cssStyle
-
-
addBottomToolbar
public void addBottomToolbar(AbstractToolbar toolbar)
Adds a toolbar to the datatable that will be displayed after the data- Parameters:
toolbar
- toolbar to be added- See Also:
AbstractToolbar
-
addTopToolbar
public void addTopToolbar(AbstractToolbar toolbar)
Adds a toolbar to the datatable that will be displayed before the data- Parameters:
toolbar
- toolbar to be added- See Also:
AbstractToolbar
-
getTopToolbars
public final WebMarkupContainer getTopToolbars()
- Returns:
- the container with the toolbars at the top
-
getBottomToolbars
public final WebMarkupContainer getBottomToolbars()
- Returns:
- the container with the toolbars at the bottom
-
getBody
public final WebMarkupContainer getBody()
- Returns:
- the container used for the table body
-
getCaption
public final DataTable.Caption getCaption()
- Returns:
- the component used for the table caption
-
getDataProvider
public final IDataProvider<T> getDataProvider()
- Returns:
- dataprovider
-
getColumns
public final List<? extends IColumn<T,S>> getColumns()
- Returns:
- array of column objects this table displays
-
getCurrentPage
public final long getCurrentPage()
- Specified by:
getCurrentPage
in interfaceIPageable
- Returns:
- The current page that is or will be rendered (page number is zero-based)
- See Also:
IPageable.getCurrentPage()
-
getPageCount
public final long getPageCount()
Description copied from interface:IPageable
Gets the total number of pages this pageable object has.- Specified by:
getPageCount
in interfaceIPageable
- Returns:
- The total number of pages this pageable object has
- See Also:
IPageable.getPageCount()
-
getRowCount
public final long getRowCount()
- Returns:
- total number of rows in this table
-
getItemsPerPage
public final long getItemsPerPage()
Description copied from interface:IPageableItems
maximum number of visible items per page- Specified by:
getItemsPerPage
in interfaceIPageableItems
- Returns:
- number of rows per page
-
setCurrentPage
public final void setCurrentPage(long page)
Description copied from interface:IPageable
Sets the a page that should be rendered (page number is zero-based)- Specified by:
setCurrentPage
in interfaceIPageable
- Parameters:
page
- The page that should be rendered.- See Also:
IPageable.setCurrentPage(long)
-
setItemReuseStrategy
public final DataTable<T,S> setItemReuseStrategy(IItemReuseStrategy strategy)
Sets the item reuse strategy. This strategy controls the creation ofItem
s.- Parameters:
strategy
- item reuse strategy- Returns:
- this for chaining
- See Also:
RefreshingView.setItemReuseStrategy(IItemReuseStrategy)
,IItemReuseStrategy
-
setItemsPerPage
public void setItemsPerPage(long items)
Sets the number of items to be displayed per page- Specified by:
setItemsPerPage
in interfaceIPageableItems
- Parameters:
items
- number of items to display per page
-
getItemCount
public long getItemCount()
Description copied from interface:IPageableItems
Gets the total number of items this object has.- Specified by:
getItemCount
in interfaceIPageableItems
- Returns:
- The total number of items this object has.
- See Also:
IPageableItems.getItemCount()
-
newCellItem
protected Item<IColumn<T,S>> newCellItem(String id, int index, IModel<IColumn<T,S>> model)
Factory method for Item container that represents a cell in the underlying DataGridView- Parameters:
id
- component id for the new data itemindex
- the index of the new data itemmodel
- the model for the new data item- Returns:
- DataItem created DataItem
- See Also:
Item
-
newRowItem
protected Item<T> newRowItem(String id, int index, IModel<T> model)
Factory method for Item container that represents a row in the underlying DataGridView- Parameters:
id
- component id for the new data itemindex
- the index of the new data itemmodel
- the model for the new data item.- Returns:
- DataItem created DataItem
- See Also:
Item
-
onDetach
protected void onDetach()
Description copied from class:Component
Called to allow a component to detach resources after use. Overrides of this method MUST call the super implementation, the most logical place to do this is the last line of the override method.- Overrides:
onDetach
in classMarkupContainer
- See Also:
Component.onDetach()
-
onPageChanged
protected void onPageChanged()
Event listener for page-changed event
-
onComponentTag
protected void onComponentTag(ComponentTag tag)
Description copied from class:Component
Processes the component tag. Overrides of this method most likely should call the super implementation.- Overrides:
onComponentTag
in classComponent
- Parameters:
tag
- Tag to modify
-
-