Wt: Wt::WTreeTable Class Reference

Wt 3.3.0

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

- Class List
- Class Hierarchy
- Class Members

Public Member Functions | Protected Member Functions
Wt::WTreeTable Class Reference

A table with a navigatable tree in the first column. More...

`#include <Wt/WTreeTable>`

Inheritance diagram for Wt::WTreeTable:
[legend]

List of all members.

## Public Member Functions
| WTreeTable (WContainerWidget *parent=0)
| Creates a new tree table.
void | addColumn (const WString &header, const WLength &width)
| Adds an extra column.
int | columnCount () const
| Returns the number of columns in this table.
void | setTreeRoot (WTreeTableNode *root, const WString &header)
| Sets the tree root.
WTreeTableNode * | treeRoot ()
| Returns the tree root.
void | setTree (WTree *tree, const WString &header)
| Sets the tree which provides the data for the tree table.
WTree * | tree () const
| Returns the tree that provides the data this table.
WLength | columnWidth (int column) const
| Returns the column width for the given column.
WText * | header (int column) const
| Returns the header for the given column.
WWidget * | headerWidget () const
| Returns the header widget.
## Protected Member Functions
virtual void | render (WFlags< RenderFlag > flags)
| Renders the widget.

## Detailed Description

A table with a navigatable tree in the first column.

A WTreeTable implements a tree table, where additional data associated is associated with tree items, which are organized in columns.

Unlike the MVC-based WTreeView widget, the tree renders a widget hierarchy, rather than a hierarhical standard model. This provides extra flexibility (as any widget can be used as contents), at the cost of server-side, client-side and bandwidth resources (especially for large tree tables).

The actual data is organized and provided by WTreeTableNode widgets.

To use the tree table, you need first to call addColumn() to specify the additional data columns. Next, you need to set the tree root using setTreeRoot() and bind additional information (text or other widgets) in each node using WTreeTableNode::setColumnWidget(). Thus, you cannot change the number of columns once the tree root has been set.

The table cannot be given a height using CSS style rules, instead you must use layout managers, or use resize().

Usage example:

     Wt::WTreeTable *treeTable = new Wt::WTreeTable();
     treeTable->resize(650, 300);

     // Add 3 extra columns
     treeTable->addColumn("Yuppie Factor", 125);
     treeTable->addColumn("# Holidays", 125);
     treeTable->addColumn("Favorite Item", 125);

     // Create and set the root node
     Wt::WTreeTableNode *root = new Wt::WTreeTableNode("All Personnel");
     root->setImagePack("resources/");
     treeTable->setTreeRoot(root, "Emweb Organigram");

     // Populate the tree with data nodes.
     Wt::WTreeTableNode *node1 = new Wt::WTreeTableNode("Upper Management", 0, root);
     Wt::WTreeTableNode *node2;
     node2 = new Wt::WTreeTableNode("Chief Anything Officer", 0, node1);
     node2->setColumnWidget(1, new Wt::WText("-2.8"));
     node2->setColumnWidget(2, new Wt::WText("20"));
     node2->setColumnWidget(3, new Wt::WText("Scepter"));

     node2 = new WTreeTableNode("Vice President of Parties", 0, node1);
     node2->setColumnWidget(1, new Wt::WText("13.57"));
     node2->setColumnWidget(2, new Wt::WText("365"));
     node2->setColumnWidget(3, new Wt::WText("Flag"));

     root->expand();

A screenshot of the treetable:

An example WTreeTable (default)
An example WTreeTable (polished)

See also:
  WTreeTableNode, WTreeView

## Constructor & Destructor Documentation

Wt::WTreeTable::WTreeTable | ( | WContainerWidget * | parent = `0` | ) |

Creates a new tree table.

The treeRoot() is `0`. The table should first be properly dimensioned using addColumn() calls, and then data using setTreeRoot().

## Member Function Documentation

void Wt::WTreeTable::addColumn | ( | const WString & | header,
|  | const WLength & | width
| ) |  |

Adds an extra column.

Add an extra column, specifying the column header and a column width. The extra columns are numbered from 1 as column 0 contains the tree itself. The header for column 0 (the tree itself) is specified in setTreeRoot(), and the width of column 0 takes the remaining available width.

int Wt::WTreeTable::columnCount | ( |  | ) | const

Returns the number of columns in this table.

Returns the number of columns in the table, including in the count column 0 (which contains the tree).

See also:
  addColumn()

WLength Wt::WTreeTable::columnWidth | ( | int | column | ) | const

Returns the column width for the given column.

The width of the first column (with index 0), containing the tree, is implied by the width set for the table minus the width of all other columns.

See also:
  addColumn(), setTreeRoot()

WText * Wt::WTreeTable::header | ( | int | column | ) | const

Returns the header for the given column.

See also:
  addColumn(), setTreeRoot()

WWidget * Wt::WTreeTable::headerWidget | ( |  | ) | const

Returns the header widget.

This is the widget that contains the column headers.

void Wt::WTreeTable::render | ( | WFlags< RenderFlag > | flags | ) | `[protected, 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::WTreeTable::setTree | ( | WTree * | tree,
|  | const WString & | header
| ) |  |

Sets the tree which provides the data for the tree table.

See also:
  setTreeRoot().

void Wt::WTreeTable::setTreeRoot | ( | WTreeTableNode * | root,
|  | const WString & | header
| ) |  |

Sets the tree root.

Sets the data for the tree table, and specify the header for the first column.

The initial `root` is `0`.

See also:
  treeRoot(), setTree()

WTree* Wt::WTreeTable::tree | ( |  | ) | const

Returns the tree that provides the data this table.

See also:
  setTree().

All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator