public class

CellTable

extends AbstractHasData<T>
java.lang.Object
   ↳ com.google.gwt.user.client.ui.UIObject
     ↳ com.google.gwt.user.client.ui.Widget
       ↳ com.google.gwt.user.cellview.client.AbstractHasData<T>
         ↳ com.google.gwt.user.cellview.client.CellTable<T>

Class Overview

A tabular view that supports paging and columns.

Columns

The Column class defines the Cell used to render a column. Implement getValue(Object) to retrieve the field value from the row object that will be rendered in the Cell.

Headers and Footers

A Header can be placed at the top (header) or bottom (footer) of the CellTable. You can specify a header as text using addColumn(Column, String), or you can create a custom Header that can change with the value of the cells, such as a column total. The Header will be rendered every time the row data changes or the table is redrawn. If you pass the same header instance (==) into adjacent columns, the header will span the columns.

Examples

Trivial example
{@example com.google.gwt.examples.cellview.CellTableExample}
FieldUpdater example
{@example com.google.gwt.examples.cellview.CellTableFieldUpdaterExample}
Key provider example
{@example com.google.gwt.examples.view.KeyProviderExample}

Summary

Nested Classes
interface CellTable.BasicResources Resources that match the GWT standard style theme. 
interface CellTable.Resources A ClientBundle that provides images for this widget. 
interface CellTable.Style Styles used by this widget. 
[Expand]
Inherited Constants
From class com.google.gwt.user.client.ui.UIObject
Public Constructors
CellTable()
Constructs a table with a default page size of 15.
CellTable(int pageSize)
Constructs a table with the given page size.
CellTable(ProvidesKey<T> keyProvider)
Constructs a table with a default page size of 15, and the given key provider.
CellTable(int pageSize, CellTable.Resources resources)
Constructs a table with the given page size with the specified CellTable.Resources.
CellTable(int pageSize, ProvidesKey<T> keyProvider)
Constructs a table with the given page size and the given key provider.
CellTable(int pageSize, CellTable.Resources resources, ProvidesKey<T> keyProvider)
Constructs a table with the given page size, the specified CellTable.Resources, and the given key provider.
Public Methods
void addColumn(Column<T, ?> col, Header<?> header, Header<?> footer)
Adds a column to the end of the table with an associated header and footer.
void addColumn(Column<T, ?> col, String headerString, String footerString)
Adds a column to the end of the table with an associated String header and footer.
void addColumn(Column<T, ?> col, String headerString)
Adds a column to the end of the table with an associated String header.
void addColumn(Column<T, ?> col, Header<?> header)
Adds a column to the end of the table with an associated header.
void addColumn(Column<T, ?> col, SafeHtml headerHtml)
Adds a column to the end of the table with an associated SafeHtml header.
void addColumn(Column<T, ?> col, SafeHtml headerHtml, SafeHtml footerHtml)
Adds a column to the end of the table with an associated SafeHtml header and footer.
void addColumn(Column<T, ?> col)
Adds a column to the end of the table.
HandlerRegistration addColumnSortHandler(ColumnSortEvent.Handler handler)
Add a handler to handle ColumnSortEvents.
void addColumnStyleName(int index, String styleName)
Add a style name to the TableColElement at the specified index, creating it if necessary.
void clearColumnWidth(Column<T, ?> column)
Clear the width of the specified Column.
int getBodyHeight()
Return the height of the table body.
Column<T, ?> getColumn(int col)
Get the column at the specified index.
int getColumnCount()
Get the number of columns in the table.
int getColumnIndex(Column<T, ?> column)
Get the index of the specified column.
ColumnSortList getColumnSortList()
Get the ColumnSortList that specifies which columns are sorted.
int getHeaderHeight()
Return the height of the table header.
TableRowElement getRowElement(int row)
Get the TableRowElement for the specified row.
void insertColumn(int beforeIndex, Column<T, ?> col, String headerString)
Inserts a column into the table at the specified index with an associated String header.
void insertColumn(int beforeIndex, Column<T, ?> col, Header<?> header)
Inserts a column into the table at the specified index with an associated header.
void insertColumn(int beforeIndex, Column<T, ?> col, SafeHtml headerHtml, SafeHtml footerHtml)
Inserts a column into the table at the specified index with an associated SafeHtml header and footer.
void insertColumn(int beforeIndex, Column<T, ?> col, Header<?> header, Header<?> footer)
Inserts a column into the table at the specified index with an associated header and footer.
void insertColumn(int beforeIndex, Column<T, ?> col)
Inserts a column into the table at the specified index.
void insertColumn(int beforeIndex, Column<T, ?> col, SafeHtml headerHtml)
Inserts a column into the table at the specified index with an associated SafeHtml header.
void insertColumn(int beforeIndex, Column<T, ?> col, String headerString, String footerString)
Inserts a column into the table at the specified index with an associated String header and footer.
void redraw()
Redraw the widget using the existing data.
void redrawFooters()
Redraw the table's footers.
void redrawHeaders()
Redraw the table's headers.
void removeColumn(int index)
Remove a column.
void removeColumn(Column<T, ?> col)
Remove a column.
void removeColumnStyleName(int index, String styleName)
Remove a style from the TableColElement at the specified index.
void setColumnWidth(Column<T, ?> column, double width, Style.Unit unit)
Set the width of a Column.
void setColumnWidth(Column<T, ?> column, String width)
Set the width of a Column.
void setRowStyles(RowStyles<T> rowStyles)
Sets the object used to determine how a row is styled; the change will take effect the next time that the table is rendered.
void setTableLayoutFixed(boolean isFixed)

Enable or disable fixed table layout.

final void setWidth(String width, boolean isFixedLayout)
Set the width of the width and specify whether or not it should use fixed table layout.
Protected Methods
Element convertToElements(SafeHtml html)
Convert the specified HTML into DOM elements and return the parent of the DOM elements.
boolean dependsOnSelection()
Check whether or not the cells in the view depend on the selection state.
void doSelection(Event event, T value, int row, int column)
Element getChildContainer()
Return the element that holds the rendered cells.
Element getKeyboardSelectedElement()
Get the element that has keyboard selection.
boolean isKeyboardNavigationSuppressed()
Check if keyboard navigation is being suppressed, such as when the user is editing a cell.
void onBlur()
Called when the widget is blurred.
void onBrowserEvent2(Event event)
Called after onBrowserEvent(Event) completes.
void onFocus()
Called when the widget is focused.
void renderRowValues(SafeHtmlBuilder sb, List<T> values, int start, SelectionModel<? super T> selectionModel)
Render all row values into the specified SafeHtmlBuilder.
void replaceAllChildren(List<T> values, SafeHtml html)
Replace all children with the specified html.
boolean resetFocusOnCell()
Reset focus on the currently focused cell.
void setKeyboardSelected(int index, boolean selected, boolean stealFocus)
Update an element to reflect its keyboard selected state.
void setSelected(Element elem, boolean selected)
This method is deprecated. this method is never called by AbstractHasData, render the selected styles in renderRowValues(SafeHtmlBuilder, List, int, SelectionModel)
[Expand]
Inherited Methods
From class com.google.gwt.user.cellview.client.AbstractHasData
From class com.google.gwt.user.client.ui.Widget
From class com.google.gwt.user.client.ui.UIObject
From class java.lang.Object
From interface com.google.gwt.event.logical.shared.HasAttachHandlers
From interface com.google.gwt.event.shared.HasHandlers
From interface com.google.gwt.user.cellview.client.HasKeyboardPagingPolicy
From interface com.google.gwt.user.cellview.client.HasKeyboardSelectionPolicy
From interface com.google.gwt.user.client.EventListener
From interface com.google.gwt.user.client.ui.Focusable
From interface com.google.gwt.user.client.ui.IsWidget
From interface com.google.gwt.view.client.HasCellPreviewHandlers
From interface com.google.gwt.view.client.HasData
From interface com.google.gwt.view.client.HasKeyProvider
From interface com.google.gwt.view.client.HasRows

Public Constructors

public CellTable ()

Constructs a table with a default page size of 15.

public CellTable (int pageSize)

Constructs a table with the given page size.

Parameters
pageSize the page size

public CellTable (ProvidesKey<T> keyProvider)

Constructs a table with a default page size of 15, and the given key provider.

Parameters
keyProvider an instance of ProvidesKey, or null if the record object should act as its own key

public CellTable (int pageSize, CellTable.Resources resources)

Constructs a table with the given page size with the specified CellTable.Resources.

Parameters
pageSize the page size
resources the resources to use for this widget

public CellTable (int pageSize, ProvidesKey<T> keyProvider)

Constructs a table with the given page size and the given key provider.

Parameters
pageSize the page size
keyProvider an instance of ProvidesKey, or null if the record object should act as its own key

public CellTable (int pageSize, CellTable.Resources resources, ProvidesKey<T> keyProvider)

Constructs a table with the given page size, the specified CellTable.Resources, and the given key provider.

Parameters
pageSize the page size
resources the resources to use for this widget
keyProvider an instance of ProvidesKey, or null if the record object should act as its own key

Public Methods

public void addColumn (Column<T, ?> col, Header<?> header, Header<?> footer)

Adds a column to the end of the table with an associated header and footer.

Parameters
col the column to be added
header the associated Header
footer the associated footer (as a Header object)

public void addColumn (Column<T, ?> col, String headerString, String footerString)

Adds a column to the end of the table with an associated String header and footer.

Parameters
col the column to be added
headerString the associated header text, as a String
footerString the associated footer text, as a String

public void addColumn (Column<T, ?> col, String headerString)

Adds a column to the end of the table with an associated String header.

Parameters
col the column to be added
headerString the associated header text, as a String

public void addColumn (Column<T, ?> col, Header<?> header)

Adds a column to the end of the table with an associated header.

Parameters
col the column to be added
header the associated Header

public void addColumn (Column<T, ?> col, SafeHtml headerHtml)

Adds a column to the end of the table with an associated SafeHtml header.

Parameters
col the column to be added
headerHtml the associated header text, as safe HTML

public void addColumn (Column<T, ?> col, SafeHtml headerHtml, SafeHtml footerHtml)

Adds a column to the end of the table with an associated SafeHtml header and footer.

Parameters
col the column to be added
headerHtml the associated header text, as safe HTML
footerHtml the associated footer text, as safe HTML

public void addColumn (Column<T, ?> col)

Adds a column to the end of the table.

Parameters
col the column to be added

public HandlerRegistration addColumnSortHandler (ColumnSortEvent.Handler handler)

Add a handler to handle ColumnSortEvents.

Parameters
handler the ColumnSortEvent.Handler to add
Returns

public void addColumnStyleName (int index, String styleName)

Add a style name to the TableColElement at the specified index, creating it if necessary.

Parameters
index the column index
styleName the style name to add

public void clearColumnWidth (Column<T, ?> column)

Clear the width of the specified Column.

Parameters
column the column

public int getBodyHeight ()

Return the height of the table body.

Returns
  • an int representing the body height

public Column<T, ?> getColumn (int col)

Get the column at the specified index.

Parameters
col the index of the column to retrieve
Returns

public int getColumnCount ()

Get the number of columns in the table.

Returns
  • the column count

public int getColumnIndex (Column<T, ?> column)

Get the index of the specified column.

Parameters
column the column to search for
Returns
  • the index of the column, or -1 if not found

public ColumnSortList getColumnSortList ()

Get the ColumnSortList that specifies which columns are sorted. Modifications to the ColumnSortList will be reflected in the table header.

Returns

public int getHeaderHeight ()

Return the height of the table header.

Returns
  • an int representing the header height

public TableRowElement getRowElement (int row)

Get the TableRowElement for the specified row. If the row element has not been created, null is returned.

Parameters
row the row index
Returns
  • the row element, or null if it doesn't exists
Throws
IndexOutOfBoundsException if the row index is outside of the current page

public void insertColumn (int beforeIndex, Column<T, ?> col, String headerString)

Inserts a column into the table at the specified index with an associated String header.

Parameters
beforeIndex the index to insert the column
col the column to be added
headerString the associated header text, as a String

public void insertColumn (int beforeIndex, Column<T, ?> col, Header<?> header)

Inserts a column into the table at the specified index with an associated header.

Parameters
beforeIndex the index to insert the column
col the column to be added
header the associated Header

public void insertColumn (int beforeIndex, Column<T, ?> col, SafeHtml headerHtml, SafeHtml footerHtml)

Inserts a column into the table at the specified index with an associated SafeHtml header and footer.

Parameters
beforeIndex the index to insert the column
col the column to be added
headerHtml the associated header text, as safe HTML
footerHtml the associated footer text, as safe HTML

public void insertColumn (int beforeIndex, Column<T, ?> col, Header<?> header, Header<?> footer)

Inserts a column into the table at the specified index with an associated header and footer.

Parameters
beforeIndex the index to insert the column
col the column to be added
header the associated Header
footer the associated footer (as a Header object)
Throws
IndexOutOfBoundsException if the index is out of range

public void insertColumn (int beforeIndex, Column<T, ?> col)

Inserts a column into the table at the specified index.

Parameters
beforeIndex the index to insert the column
col the column to be added

public void insertColumn (int beforeIndex, Column<T, ?> col, SafeHtml headerHtml)

Inserts a column into the table at the specified index with an associated SafeHtml header.

Parameters
beforeIndex the index to insert the column
col the column to be added
headerHtml the associated header text, as safe HTML

public void insertColumn (int beforeIndex, Column<T, ?> col, String headerString, String footerString)

Inserts a column into the table at the specified index with an associated String header and footer.

Parameters
beforeIndex the index to insert the column
col the column to be added
headerString the associated header text, as a String
footerString the associated footer text, as a String

public void redraw ()

Redraw the widget using the existing data.

public void redrawFooters ()

Redraw the table's footers.

public void redrawHeaders ()

Redraw the table's headers.

public void removeColumn (int index)

Remove a column.

Parameters
index the column index

public void removeColumn (Column<T, ?> col)

Remove a column.

Parameters
col the column to remove

public void removeColumnStyleName (int index, String styleName)

Remove a style from the TableColElement at the specified index.

Parameters
index the column index
styleName the style name to remove

public void setColumnWidth (Column<T, ?> column, double width, Style.Unit unit)

Set the width of a Column. The layout behavior depends on whether or not the table is using fixed layout.

Parameters
column the column
width the width of the column
unit the Style.Unit of measurement

public void setColumnWidth (Column<T, ?> column, String width)

Set the width of a Column. The layout behavior depends on whether or not the table is using fixed layout.

Parameters
column the column
width the width of the column

public void setRowStyles (RowStyles<T> rowStyles)

Sets the object used to determine how a row is styled; the change will take effect the next time that the table is rendered.

Parameters
rowStyles a RowStyles object

public void setTableLayoutFixed (boolean isFixed)

Enable or disable fixed table layout.

Fixed Table Layout

When using the fixed table layout, cell contents are truncated as needed, which allows you to set the exact width of columns and the table. The default column width is 0 (invisible). In order to see all columns, you must set the width of the table (recommended 100%), or set the width of every column in the table. The following conditions are true for fixed layout tables:
  • If the widths of all columns are set, the width becomes a weight and the columns are resized proportionally.
  • If the widths of some columns are set using absolute values (PX), those columns are fixed and the remaining width is divided evenly over the other columns. If there is no remaining width, the other columns will not be visible.
  • If the width of some columns are set in absolute values (PX) and others are set in relative values (PCT), the absolute columns will be fixed and the remaining width is divided proportionally over the PCT columns. This allows users to define how the remaining width is allocated.

Parameters
isFixed true to use fixed table layout, false not to

public final void setWidth (String width, boolean isFixedLayout)

Set the width of the width and specify whether or not it should use fixed table layout. See setTableLayoutFixed(boolean) for more information about fixed layout tables.

Parameters
width the width of the table
isFixedLayout true to use fixed width layout, false not to

Protected Methods

protected Element convertToElements (SafeHtml html)

Convert the specified HTML into DOM elements and return the parent of the DOM elements.

Parameters
html the HTML to convert
Returns
  • the parent element

protected boolean dependsOnSelection ()

Check whether or not the cells in the view depend on the selection state.

Returns
  • true if cells depend on selection, false if not

protected void doSelection (Event event, T value, int row, int column)

This method is deprecated.
use addCellPreviewHandler(com.google.gwt.view.client.CellPreviewEvent.Handler) instead

Called when a user action triggers selection.

Parameters
event the event that triggered selection
value the value that was selected
row the row index of the value on the page
column the column index where the event occurred

protected Element getChildContainer ()

Return the element that holds the rendered cells.

Returns

protected Element getKeyboardSelectedElement ()

Get the element that has keyboard selection.

Returns
  • the keyboard selected element

protected boolean isKeyboardNavigationSuppressed ()

Check if keyboard navigation is being suppressed, such as when the user is editing a cell.

Returns
  • true if suppressed, false if not

protected void onBlur ()

Called when the widget is blurred.

protected void onBrowserEvent2 (Event event)

Called after onBrowserEvent(Event) completes.

Parameters
event the event that was fired

protected void onFocus ()

Called when the widget is focused.

protected void renderRowValues (SafeHtmlBuilder sb, List<T> values, int start, SelectionModel<? super T> selectionModel)

Render all row values into the specified SafeHtmlBuilder.

Parameters
sb the SafeHtmlBuilder to render into
values the row values
start the absolute start index of the values
selectionModel the SelectionModel

protected void replaceAllChildren (List<T> values, SafeHtml html)

Replace all children with the specified html.

Parameters
values the values of the new children
html the html to render in the child

protected boolean resetFocusOnCell ()

Reset focus on the currently focused cell.

Returns
  • true if focus is taken, false if not

protected void setKeyboardSelected (int index, boolean selected, boolean stealFocus)

Update an element to reflect its keyboard selected state.

Parameters
index the index of the element
selected true if selected, false if not
stealFocus true if the row should steal focus, false if not

protected void setSelected (Element elem, boolean selected)

This method is deprecated.
this method is never called by AbstractHasData, render the selected styles in renderRowValues(SafeHtmlBuilder, List, int, SelectionModel)

Update an element to reflect its selected state.

Parameters
elem the element to update
selected true if selected, false if not