Module org.apache.wicket.extensions
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<org.apache.wicket.Component>,org.apache.wicket.event.IEventSink,org.apache.wicket.event.IEventSource,org.apache.wicket.feedback.IFeedbackContributor,org.apache.wicket.IConverterLocator,org.apache.wicket.IMetadataContext<Serializable,,org.apache.wicket.Component> org.apache.wicket.IQueueRegion,org.apache.wicket.markup.html.IHeaderContributor,org.apache.wicket.markup.html.navigation.paging.IPageable,org.apache.wicket.markup.html.navigation.paging.IPageableItems,org.apache.wicket.request.component.IRequestableComponent,org.apache.wicket.util.IHierarchical<org.apache.wicket.Component>,org.apache.wicket.util.io.IClusterable
- Direct Known Subclasses:
AjaxFallbackDefaultDataTable,DefaultDataTable
public class DataTable<T,S>
extends org.apache.wicket.markup.html.panel.Panel
implements org.apache.wicket.markup.html.navigation.paging.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:
-
Nested Class Summary
Nested Classes -
Field Summary
Fields inherited from class org.apache.wicket.markup.html.panel.Panel
PANELFields 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 -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddBottomToolbar(AbstractToolbar toolbar) Adds a toolbar to the datatable that will be displayed after the datavoidaddTopToolbar(AbstractToolbar toolbar) Adds a toolbar to the datatable that will be displayed before the datafinal org.apache.wicket.markup.html.WebMarkupContainergetBody()final org.apache.wicket.markup.html.WebMarkupContainerfinal DataTable.Captionprotected org.apache.wicket.model.IModel<String>Returns the model for table's caption.final ColGroupfinal longfinal org.apache.wicket.markup.repeater.data.IDataProvider<T>longfinal longfinal longfinal longfinal org.apache.wicket.markup.html.WebMarkupContainerprotected org.apache.wicket.markup.html.WebMarkupContainerCreate the MarkupContainer for the tag.newCellItem(String id, int index, org.apache.wicket.model.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, org.apache.wicket.markup.repeater.data.IDataProvider<T> dataProvider) Factory method for the DataGridViewprotected org.apache.wicket.markup.repeater.Item<T>newRowItem(String id, int index, org.apache.wicket.model.IModel<T> model) Factory method for Item container that represents a row in the underlying DataGridViewprotected voidonComponentTag(org.apache.wicket.markup.ComponentTag tag) protected voidonDetach()protected voidEvent listener for page-changed eventfinal voidsetCurrentPage(long page) setItemReuseStrategy(org.apache.wicket.markup.repeater.IItemReuseStrategy strategy) Sets the item reuse strategy.voidsetItemsPerPage(long items) Sets the number of items to be displayed per pagefinal voidsetTableBodyCss(String cssStyle) Set the 'class' attribute for the tbody tag.Methods inherited from class org.apache.wicket.markup.html.panel.Panel
getRegionMarkup, newMarkupSourcingStrategyMethods inherited from class org.apache.wicket.markup.html.WebMarkupContainer
getWebApplication, getWebPage, getWebRequest, getWebResponse, getWebSessionMethods 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, renderNext, replace, setDefaultModel, size, stream, streamChildren, toString, toString, visitChildren, visitChildrenMethods 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, wrapMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.apache.wicket.IQueueRegion
dequeue, newDequeueContextMethods inherited from interface java.lang.Iterable
forEach, spliterator
-
Constructor Details
-
DataTable
public DataTable(String id, List<? extends IColumn<T, S>> columns, org.apache.wicket.markup.repeater.data.IDataProvider<T> dataProvider, long rowsPerPage) Constructor- Parameters:
id- component idcolumns- list of IColumn objectsdataProvider- imodel for data providerrowsPerPage- number of rows per page
-
-
Method Details
-
newDataGridView
protected DataGridView<T> newDataGridView(String id, List<? extends IColumn<T, S>> columns, org.apache.wicket.markup.repeater.data.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
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
-
newBodyContainer
Create the MarkupContainer for the tag. Developers may subclass it to provide their own (modified) implementation.- Parameters:
id-- Returns:
- A new markup container
setTableBodyCss
Set the 'class' attribute for the tbody tag.- Parameters:
cssStyle-
addBottomToolbar
Adds a toolbar to the datatable that will be displayed after the data- Parameters:
toolbar- toolbar to be added- See Also:
addTopToolbar
Adds a toolbar to the datatable that will be displayed before the data- Parameters:
toolbar- toolbar to be added- See Also:
getTopToolbars
- Returns:
- the container with the toolbars at the top
getBottomToolbars
- Returns:
- the container with the toolbars at the bottom
getBody
- Returns:
- the container used for the table body
getCaption
- Returns:
- the component used for the table caption
getDataProvider
- Returns:
- dataprovider
getColumns
- Returns:
- array of column objects this table displays
getCurrentPage
- Specified by:
getCurrentPagein interfaceorg.apache.wicket.markup.html.navigation.paging.IPageable- See Also:
-
IPageable.getCurrentPage()
getPageCount
- Specified by:
getPageCountin interfaceorg.apache.wicket.markup.html.navigation.paging.IPageable- See Also:
-
IPageable.getPageCount()
getRowCount
- Returns:
- total number of rows in this table
getItemsPerPage
- Specified by:
getItemsPerPagein interfaceorg.apache.wicket.markup.html.navigation.paging.IPageableItems- Returns:
- number of rows per page
setCurrentPage
- Specified by:
setCurrentPagein interfaceorg.apache.wicket.markup.html.navigation.paging.IPageable- See Also:
-
IPageable.setCurrentPage(long)
setItemReuseStrategy
public final DataTable<T,S> setItemReuseStrategy(org.apache.wicket.markup.repeater.IItemReuseStrategy strategy) Sets the item reuse strategy. This strategy controls the creation ofItems.- Parameters:
strategy- item reuse strategy- Returns:
- this for chaining
- See Also:
-
RefreshingView.setItemReuseStrategy(IItemReuseStrategy)IItemReuseStrategy
setItemsPerPage
Sets the number of items to be displayed per page- Specified by:
setItemsPerPagein interfaceorg.apache.wicket.markup.html.navigation.paging.IPageableItems- Parameters:
items- number of items to display per page
getItemCount
- Specified by:
getItemCountin interfaceorg.apache.wicket.markup.html.navigation.paging.IPageableItems- See Also:
-
IPageableItems.getItemCount()
newCellItem
protected org.apache.wicket.markup.repeater.Item<IColumn<T,S>> newCellItem(String id, int index, org.apache.wicket.model.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 org.apache.wicket.markup.repeater.Item<T> newRowItem(String id, int index, org.apache.wicket.model.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
- Overrides:
onDetachin classorg.apache.wicket.MarkupContainer- See Also:
-
Component.onDetach()
onPageChanged
Event listener for page-changed eventonComponentTag
- Overrides:
onComponentTagin classorg.apache.wicket.Component
-