Wt: Wt::WTableView Class Reference

Wt 3.3.0

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes

- Class List
- Class Hierarchy
- Class Members

Public Member Functions | Private Member Functions
Wt::WTableView Class Reference
Model/view system

An MVC View widget for tabular data. More...

`#include <Wt/WTableView>`

Inheritance diagram for Wt::WTableView:
[legend]

List of all members.

## Public Member Functions
| WTableView (WContainerWidget *parent=0)
| Constructor.
virtual WWidget * | itemWidget (const WModelIndex &index) const
| Returns the widget that renders an item.
virtual void | setModel (WAbstractItemModel *model)
| Sets the model.
virtual void | setColumnWidth (int column, const WLength &width)
| Sets the column width.
virtual void | setAlternatingRowColors (bool enable)
| Sets if alternating row colors are to be used.
virtual void | setRowHeight (const WLength &rowHeight)
| Sets the row height.
virtual void | setHeaderHeight (const WLength &height)
| Sets the header height.
virtual void | setColumnBorder (const WColor &color)
| Sets the column border color.
virtual void | resize (const WLength &width, const WLength &height)
| Resizes the widget.
virtual void | setColumnHidden (int column, bool hidden)
| Changes the visibility of a column.
virtual void | setRowHeaderCount (int count)
| Configures the number of columns that are used as row headers.
virtual int | pageCount () const
| Returns the number of pages.
virtual int | pageSize () const
| Returns the page size.
virtual int | currentPage () const
| Returns the current page.
virtual void | setCurrentPage (int page)
| Sets the current page.
virtual void | scrollTo (const WModelIndex &index, ScrollHint hint=EnsureVisible)
| Scrolls the view to an item.
virtual void | setHidden (bool hidden, const WAnimation &animation=WAnimation())
| Hides or shows the widget.
## Private Member Functions
virtual void | render (WFlags< RenderFlag > flags)
| Renders the widget.

## Detailed Description

An MVC View widget for tabular data.

The view displays data from a WAbstractItemModel in a table. It provides incremental rendering, without excessive use of client- or serverside resources.

The rendering (and editing) of items is handled by a WAbstractItemDelegate, by default it uses WItemDelegate which renders data of all predefined roles (see also Wt::ItemDataRole), including text, icons, checkboxes, and tooltips.

The view provides virtual scrolling in both horizontal and vertical directions, and can therefore be used to display large data models (with large number of columns and rows).

The view may support editing of items, if the model indicates support (see the Wt::ItemIsEditable flag). You can define triggers that initiate editing of an item using setEditTriggers(). The actual editing is provided by the item delegate (you can set an appropriate delegate for one column using setItemDelegateForColumn()). Using setEditOptions() you can customize if and how the view deals with multiple editors.

By default, all columns are given a width of 150px. Column widths of all columns can be set through the API method setColumnWidth(), and also by the user using handles provided in the header.

If the model supports sorting (WAbstractItemModel::sort()), such as the WStandardItemModel, then you can enable sorting buttons in the header, using setSortingEnabled().

You can allow selection on row or item level (using setSelectionBehavior()), and selection of single or multiple items (using setSelectionMode()), and listen for changes in the selection using the selectionChanged() signal.

You may enable drag & drop support for this view, whith awareness of the items in the model. When enabling dragging (see setDragEnabled()), the current selection may be dragged, but only when all items in the selection indicate support for dragging (controlled by the ItemIsDragEnabled flag), and if the model indicates a mime-type (controlled by WAbstractItemModel::mimeType()). Likewise, by enabling support for dropping (see setDropsEnabled()), the view may receive a drop event on a particular item, at least if the item indicates support for drops (controlled by the ItemIsDropEnabled flag).

You may also react to mouse click events on any item, by connecting to one of the clicked() or doubleClicked() signals.

## Member Function Documentation

int Wt::WTableView::currentPage | ( |  | ) | const`[virtual]`

Returns the current page.

When Ajax/JavaScript is not available, the view will use a paging navigation bar to allow scrolling through the data. This returns the current page (between 0 and pageCount() - 1).

See also:
  createPageNavigationBar(), pageChanged()

Implements Wt::WAbstractItemView.

WWidget * Wt::WTableView::itemWidget | ( | const WModelIndex & | index | ) | const`[virtual]`

Returns the widget that renders an item.

This returns the widget that renders the given item. This may return 0 if the item is currently not rendered.

This widget has been created by an item delegate, and usually an item delegate is involved when updating it.

Implements Wt::WAbstractItemView.

int Wt::WTableView::pageCount | ( |  | ) | const`[virtual]`

Returns the number of pages.

When Ajax/JavaScript is not available, the view will use a paging navigation bar to allow scrolling through the data. This returns the number of pages currently shown.

See also:
  createPageNavigationBar(), pageChanged()

Implements Wt::WAbstractItemView.

int Wt::WTableView::pageSize | ( |  | ) | const`[virtual]`

Returns the page size.

When Ajax/JavaScript is not available, the view will use a paging navigation bar to allow scrolling through the data. This returns the number of items per page.

See also:
  createPageNavigationBar(), pageChanged()

Implements Wt::WAbstractItemView.

void Wt::WTableView::render | ( | WFlags< RenderFlag > | flags | ) | `[private, virtual]`

Renders the widget.

This function renders the widget (or an update for the widget), after this has been scheduled using scheduleRender().

The default implementation will render the widget by serializing changes to JavaScript and HTML. You may want to reimplement this widget if you have been postponing some of the layout / rendering implementation until the latest moment possible. In that case you should make sure you call the base implementation however.

Reimplemented from Wt::WCompositeWidget.

void Wt::WTableView::resize | ( | const WLength & | width,
|  | const WLength & | height
| ) |  | `[virtual]`

Resizes the widget.

Specifies a fixed size for this widget, setting CSS `width` and `height` properties. By default a widget has automatic width and height, which sets a size for the widget following CSS rules.

When the widget is not managed by a layout manager, the automatic (natural) size of a widget depends on whether they widget is a block or inline widget:

- a block widget takes by default the width of the parent, and the height that it needs based on its contents
- an inline widget takes the width and height that it needs based on its contents (possibly wrapping over multiple lines). The width and height of an inline widget cannot be changed (by the letter of CSS, although most browsers will react to it in varying ways).

When inserted in a layout manager, the size set will be used as a widget's preferred size, but the widget may be given a different size by the layout manager based on available space and stretch factors. The actual size given by a layout manager may be retrieved by making the widget "layout size aware", using setLayoutSizeAware(). If you have defined a `"wtResize()"` JavaScript method for the widget, then this method will also be called.

The default width and height of a widget is WLength::Auto.

See also:
  width(), height()

Reimplemented from Wt::WCompositeWidget.

void Wt::WTableView::scrollTo | ( | const WModelIndex & | index,
|  | ScrollHint | hint = `EnsureVisible`
| ) |  | `[virtual]`

Scrolls the view to an item.

Scrolls the view to ensure that the item which represents the provided `index` is visible. A `hint` may indicate how the item should appear in the viewport (if possible).

Note:
  Currently only implemented to scroll to the correct row, not taking into account the column.

Implements Wt::WAbstractItemView.

void Wt::WTableView::setAlternatingRowColors | ( | bool | enable | ) | `[virtual]`

Sets if alternating row colors are to be used.

Configure whether rows get alternating background colors, defined by the current CSS theme.

The default value is `false`.

Reimplemented from Wt::WAbstractItemView.

void Wt::WTableView::setColumnBorder | ( | const WColor & | color | ) | `[virtual]`

Sets the column border color.

The default border color is defined by the CSS theme.

Implements Wt::WAbstractItemView.

void Wt::WTableView::setColumnHidden | ( | int | column,
|  | bool | hide
| ) |  | `[virtual]`

Changes the visibility of a column.

See also:
  isColumnHidden()

Reimplemented from Wt::WAbstractItemView.

void Wt::WTableView::setColumnWidth | ( | int | column,
|  | const WLength & | width
| ) |  | `[virtual]`

Sets the column width.

The default column width is 150 pixels.

Note:
  The actual space occupied by each column is the column width augmented by 7 pixels for internal padding and a border.

Implements Wt::WAbstractItemView.

void Wt::WTableView::setCurrentPage | ( | int | page | ) | `[virtual]`

Sets the current page.

When Ajax/JavaScript is not available, the view will use a paging navigation bar to allow scrolling through the data. This method can be used to change the current page.

See also:
  createPageNavigationBar(), pageChanged()

Implements Wt::WAbstractItemView.

void Wt::WTableView::setHeaderHeight | ( | const WLength & | height | ) | `[virtual]`

Sets the header height.

The default value is 20 pixels.

Reimplemented from Wt::WAbstractItemView.

void Wt::WTableView::setHidden | ( | bool | hidden,
|  | const WAnimation & | animation = `WAnimation()`
| ) |  | `[virtual]`

Hides or shows the widget.

Hides or show the widget (including all its descendant widgets). When setting `hidden` = `false`, this widget and all descendant widgets that are not hidden will be shown. A widget is only visible if it and all its ancestors in the widget tree are visible, which may be checked using isVisible().

Reimplemented from Wt::WCompositeWidget.

void Wt::WTableView::setModel | ( | WAbstractItemModel * | model | ) | `[virtual]`

Sets the model.

The View will display data of the given `model` and changes in the model are reflected by the View.

The initial model is `0`.

Ownership of the model is not transferred (and thus the previously set model is not deleted). A model may not be deleted as long as a view exists for it.

See also:
  setRootIndex()

Reimplemented from Wt::WAbstractItemView.

void Wt::WTableView::setRowHeaderCount | ( | int | count | ) | `[virtual]`

Configures the number of columns that are used as row headers.

An item view does not use the vertical header data from the model in any way, but instead you can configure data in the first column(s) to be used as a row headers.

These columns will not scroll horizontally together with the rest of the model.

The default value is 0.

Note:
  Currently, this property must be set before any other settings of the view and only a value of 0 or 1 is supported.

Reimplemented from Wt::WAbstractItemView.

void Wt::WTableView::setRowHeight | ( | const WLength & | rowHeight | ) | `[virtual]`

Sets the row height.

The view renders all rows with a same height. This method configures this row height.

The default value is 20 pixels.

Note:
  The height must be specified in WLength::Pixel units.

See also:
  setColumnWidth()

Reimplemented from Wt::WAbstractItemView.

All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator