Class WTable


public class WTable extends WInteractWidget
A container widget which provides layout of children in a table grid.

A WTable arranges its children in a table.

To insert or access contents, use getElementAt() to access the cell at a particular location in the table. The WTable expands automatically to create the indexed (row, column) as necessary.

It is possible to insert and delete entire rows or columns from the table using the insertColumn(int column), insertRow(int row), deleteColumn(int column), or deleteRow(int row) methods.

You may indicate a number of rows and columns that act as headers using setHeaderCount(). Header cells are rendered as <th> instead of <td> elements. By default, no rows or columns are configured as headers.

WTable is displayed as a block.

CSS

The widget corresponds to the HTML <table> tag and does not provide styling. It can be styled using inline or external CSS as appropriate.

See Also:
  • Constructor Details

  • Method Details

    • remove

      public void remove()
      Deletes the table and its entire contents.
      Overrides:
      remove in class WInteractWidget
      See Also:
    • getElementAt

      public WTableCell getElementAt(int row, int column)
      Accesses the table element at the given row and column.

      If the row/column is beyond the current table dimensions, then the table is expanded automatically.

    • getRowAt

      public WTableRow getRowAt(int row)
      Returns the row object for the given row.

      Like with getElementAt(), the table expands automatically when the row is beyond the current table dimensions.

      See Also:
    • getColumnAt

      public WTableColumn getColumnAt(int column)
      Returns the column object for the given column.

      Like with getElementAt(), the table expands automatically when the column is beyond the current table dimensions.

      See Also:
    • removeCell

      public void removeCell(WTableCell item)
      Deletes a table cell and its contents.

      The table cell at that position is recreated.

      See Also:
    • removeCell

      public void removeCell(int row, int column)
      Deletes the table cell at the given position.

      See Also:
    • insertRow

      public WTableRow insertRow(int row, WTableRow tableRow)
      Inserts a row.
    • insertRow

      public final WTableRow insertRow(int row)
      Inserts a row.

      Returns insertRow(row, null)

    • removeRow

      public WTableRow removeRow(int row)
      Removes a row.

      Rows below the given row are shifted up. Returns a WTableRow that is not associated with a WTable. Unlinke removeColumn(), the cells in the row will not be deleted, because they are owned by the WTableRow.

    • insertColumn

      public WTableColumn insertColumn(int column, WTableColumn tableColumn)
      Inserts an empty column.
    • insertColumn

      public final WTableColumn insertColumn(int column)
      Inserts an empty column.

      Returns insertColumn(column, null)

    • removeColumn

      public WTableColumn removeColumn(int column)
      Remove a column and all its contents.

      The contents of the column will be deleted, because a WTableColumn does not own its cells.

    • clear

      public void clear()
      Clears the entire table.

      This method clears the entire table: all cells and their contents are deleted.

    • getRowCount

      public int getRowCount()
      Returns the number of rows in the table.
    • getColumnCount

      public int getColumnCount()
      Returns the number of columns in the table.
    • setHeaderCount

      public void setHeaderCount(int count, Orientation orientation)
      Sets the number of header rows or columns.

      The default values are 0.

      Note: This must be set before the initial rendering and cannot be changed later.

    • setHeaderCount

      public final void setHeaderCount(int count)
      Sets the number of header rows or columns.

      Calls setHeaderCount(count, Orientation.Horizontal)

    • getHeaderCount

      public int getHeaderCount(Orientation orientation)
      Returns the number of header rows or columns.

      See Also:
    • getHeaderCount

      public final int getHeaderCount()
      Returns the number of header rows or columns.

      Returns getHeaderCount(Orientation.Horizontal)

    • moveRow

      public void moveRow(int from, int to)
      Move a table row from its original position to a new position.

      The table expands automatically when the to row is beyond the current table dimensions.

      See Also:
    • moveColumn

      public void moveColumn(int from, int to)
      Move a table column from its original position to a new position.

      The table expands automatically when the to column is beyond the current table dimensions.

      See Also:
    • createCell

      protected WTableCell createCell(int row, int column)
      Creates a table cell.

      You may want to override this method if you want your table to contain specialized cells.

    • createRow

      protected WTableRow createRow(int row)
      Creates a table row.

      You may want to override this method if you want your table to contain specialized rows.

    • createColumn

      protected WTableColumn createColumn(int column)
      Creates a table column.

      You may want to override this method if you want your table to contain specialized columns.

    • createDomElement

      protected DomElement createDomElement(WApplication app)
      Description copied from class: WWebWidget
      Create DOM element for widget.

      This is an internal function, and should not be called directly, or be overridden!

      Overrides:
      createDomElement in class WWebWidget
    • getDomChanges

      protected void getDomChanges(List<DomElement> result, WApplication app)
      Description copied from class: WWebWidget
      Get DOM changes for this widget.

      This is an internal function, and should not be called directly, or be overridden!

      Overrides:
      getDomChanges in class WWebWidget
    • iterateChildren

      protected void iterateChildren(HandleWidgetMethod method)
      Overrides:
      iterateChildren in class WWebWidget