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 type
S - 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
    Modifier and Type
    Class
    Description
    static class 
    A caption for the table.
  • Field Summary

    Fields inherited from class org.apache.wicket.markup.html.panel.Panel

    PANEL

    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
  • Constructor Summary

    Constructors
    Constructor
    Description
    DataTable(String id, List<? extends IColumn<T,S>> columns, org.apache.wicket.markup.repeater.data.IDataProvider<T> dataProvider, long rowsPerPage)
    Constructor
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Adds a toolbar to the datatable that will be displayed after the data
    void
    Adds a toolbar to the datatable that will be displayed before the data
    final org.apache.wicket.markup.html.WebMarkupContainer
     
    final org.apache.wicket.markup.html.WebMarkupContainer
     
     
    protected org.apache.wicket.model.IModel<String>
    Returns the model for table's caption.
    final ColGroup
     
    final List<? extends IColumn<T,S>>
     
    final long
     
    final org.apache.wicket.markup.repeater.data.IDataProvider<T>
     
    long
     
    final long
     
    final long
     
    final long
     
    final org.apache.wicket.markup.html.WebMarkupContainer
     
    protected org.apache.wicket.markup.html.WebMarkupContainer
    Create the MarkupContainer for the tag.
    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
    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
    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
    protected void
    onComponentTag(org.apache.wicket.markup.ComponentTag tag)
     
    protected void
     
    protected void
    Event listener for page-changed event
    final void
    setCurrentPage(long page)
     
    final DataTable<T,S>
    setItemReuseStrategy(org.apache.wicket.markup.repeater.IItemReuseStrategy strategy)
    Sets the item reuse strategy.
    void
    setItemsPerPage(long items)
    Sets the number of items to be displayed per page
    final void
    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, 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
  • 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 id
      columns - list of IColumn objects
      dataProvider - imodel for data provider
      rowsPerPage - 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 id
      columns - list of IColumn objects
      dataProvider - imodel for data provider
      Returns:
      the data grid view
    • getCaptionModel

      protected org.apache.wicket.model.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 org.apache.wicket.markup.html.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:
    • 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:
    • getTopToolbars

      public final org.apache.wicket.markup.html.WebMarkupContainer getTopToolbars()
      Returns:
      the container with the toolbars at the top
    • getBottomToolbars

      public final org.apache.wicket.markup.html.WebMarkupContainer getBottomToolbars()
      Returns:
      the container with the toolbars at the bottom
    • getBody

      public final org.apache.wicket.markup.html.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 org.apache.wicket.markup.repeater.data.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 interface org.apache.wicket.markup.html.navigation.paging.IPageable
      See Also:
      • IPageable.getCurrentPage()
    • getPageCount

      public final long getPageCount()
      Specified by:
      getPageCount in interface org.apache.wicket.markup.html.navigation.paging.IPageable
      See Also:
      • IPageable.getPageCount()
    • getRowCount

      public final long getRowCount()
      Returns:
      total number of rows in this table
    • getItemsPerPage

      public final long getItemsPerPage()
      Specified by:
      getItemsPerPage in interface org.apache.wicket.markup.html.navigation.paging.IPageableItems
      Returns:
      number of rows per page
    • setCurrentPage

      public final void setCurrentPage(long page)
      Specified by:
      setCurrentPage in interface org.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 of Items.
      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 interface org.apache.wicket.markup.html.navigation.paging.IPageableItems
      Parameters:
      items - number of items to display per page
    • getItemCount

      public long getItemCount()
      Specified by:
      getItemCount in interface org.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 item
      index - the index of the new data item
      model - 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 item
      index - the index of the new data item
      model - the model for the new data item.
      Returns:
      DataItem created DataItem
      See Also:
      • Item
    • onDetach

      protected void onDetach()
      Overrides:
      onDetach in class org.apache.wicket.MarkupContainer
      See Also:
      • Component.onDetach()
    • onPageChanged

      protected void onPageChanged()
      Event listener for page-changed event
    • onComponentTag

      protected void onComponentTag(org.apache.wicket.markup.ComponentTag tag)
      Overrides:
      onComponentTag in class org.apache.wicket.Component