Table — Multicolumn table widget
Table
( | term header , |
list
items
) ; |
immediate
make `notify trigger immediately when the selected item changes
keepSorting
keep the insertion order - don't let the user sort manually by clicking
multiSelection
user can select multiple items (rows) at once (shift-click, ctrl-click)
The Table widget is a selection list with multiple columns. By default, the user can select exactly one row (with all its columns) from that list. With `opt(`multiSelection), the user can select one or more rows (with all their columns) from that list (In that case, use the `SelectedItems property, not `Value).
Each cell (each column within each row) has a label text and an optional icon.
(Note: Not all UIs (in particular not text-based UIs) support displaying icons, so an icon should never be an exclusive means to display any kind of information).
This widget is similar to SelectionBox, but it has several columns for each item (each row). If just one column is desired, consider using SelectionBox instead.
Note: This is not something like a spread sheet, and it doesn't pretend or want to be. Actions are performed on rows, not on individual cells (columns within one row).
The first argument (after `opt() and `id() which both are optional) is `header() which specifies the column headers (and implicitly the number of columns) and optionally the alignment for each column. Default alignment is left.
In the list of items, an ID is specified for each item. Each item can have less cells (columns) than the table has columns (from `header()), in which case any missing cells are assumed to be empty. If an item has more cells than the table has columns, any extra cells are ignored.
Each cell has a text label (which might also be an empty string) and optionally an icon. If a cell has an icon, it has to be specified with `cell(`icon("myiconname.png", "Label text")).
A simple table is specified like this:
`Table(`id(`players), `header("Nick", "Age", "Role"), [ `item(`id("Bluebird"), "Bluebird, 18, "Scout" ), `item(`id("Ozzz" ), "Ozzz", 23, "Wizard" ), `item(`id("Wannabe" ), "Wannabe", 17 ), `item(`id("Coxxan" ), "Coxxan", 26, "Warrior") ] )
This will create a 3-column table. The first column ("Nick") and the third column ("Role") will be left aligned. The second column ("Age") will be right aligned. note that "Wannabe" doesn't have a Role. This field will be empty.
A table that uses icons is specified like this:
`Table(`id(`players), `header("Nick", "Age", "Role"), [ `item(`id("Bluebird"), "Bluebird, 18, `cell(`icon("scout.png"), "Scout" ) ), `item(`id("Ozzz" ), "Ozzz", 23, "Wizard" ), `item(`id("Wannabe" ), "Wannabe", `cell(`icon("underage.png", 17 ) ), `item(`id("Coxxan" ), "Coxxan", `cell(`icon("oldman.png", 26 ), "Warrior" ) ] )
In this example, "Bluebird" has an additional icon in his "Role" column, and "Wannabe" and "Coxxan" both have additional icons in their "Age" columns.
{ UI::OpenDialog( `VBox( `Heading("Today's menu"), `MinSize( 25, 7, `Table( `header("Name", "Price"), [ `item(`id(1), "Chili", 6), `item(`id(2), "Salami Baguette", nil), `item(`id(3), "Spaghetti", 8), `item(`id(4), "Steak Sandwich", 12) ] ) ), `PushButton("&OK") ) ); UI::UserInput(); UI::CloseDialog(); }
{ UI::OpenDialog( `VBox( `Heading("Today's menu"), `MinSize( 30, 7, `Table( `id(`table), `opt(`keepSorting), `header("Name", `Right("Price"), `Center("Rating")), [ `item(`id(0), "Steak Sandwich", 12, "+++"), `item(`id(1), "Salami Baguette", nil, "-" ), `item(`id(2), "Chili", 6, "--" ), `item(`id(3), "Spaghetti", 8, "+" ) ] ) ), `Right( `HBox( `PushButton(`id(`next), "&Next"), `PushButton(`id(`cancel), "&Close") ) ) ) ); UI::ChangeWidget(`id(`table), `CurrentItem, 2); while (UI::UserInput() != `cancel) { UI::ChangeWidget(`id(`table), `CurrentItem, ((integer) UI::QueryWidget(`id(`table), `CurrentItem) + 1) % 4); } UI::CloseDialog(); }
// Table example: Exchange complete table content { list foodItems = [ `item(`id(3), "Spaghetti", 8), `item(`id(4), "Steak Sandwich", 12), `item(`id(1), "Chili", 6), `item(`id(2), "Salami Baguette", nil) ]; list carItems = [ `item(`id(0), "Mercedes", 60000), `item(`id(1), "Audi", 50000), `item(`id(2), "VW", 40000), `item(`id(3), "BMW", 60000), `item(`id(3), "Porsche", 80000) ]; list itemLists = [ foodItems, carItems ]; integer listNo = 0; UI::OpenDialog( `VBox( `Heading("Prices"), `MinSize( 30, 10, `Table(`id(`table), `header("Name", "Price"), foodItems ) ), `Right( `HBox( `PushButton(`id(`next), "Change &Table Contents"), `PushButton(`id(`cancel), "&Close") ) ) ) ); while (UI::UserInput() != `cancel) { // Change table contents listNo = 1 - listNo; UI::ChangeWidget(`table, `Items, itemLists[ listNo ]:nil ); // Double check: Retrieve contents and dump to log y2milestone( "New table content:\n%1", UI::QueryWidget(`table, `Items ) ); } UI::CloseDialog(); }
{ UI::OpenDialog( `VBox( `Heading("Today's menu"), `MinSize( 25, 7, `Table(`id(`table), `header("Name", "Price"), [ `item(`id(1), "Chili", 6), `item(`id(2), "Salami Baguette", nil), `item(`id(3), "Spaghetti", 8), `item(`id(4), "Steak Sandwich", 12) ] ) ), `Right(`HBox( `PushButton("&Lookup"), `PushButton(`id(`cancel), "&Close" ) ) ) ) ); while (UI::UserInput() != `cancel) { any id = UI::QueryWidget(`id(`table), `CurrentItem); if (is(id, integer)) { string text = sformat("Line: %1", UI::QueryWidget(`id(`table), `Item(id))); UI::OpenDialog( `MarginBox( 1, 0.2, `VBox( `Left( `Label( "Current Table Item" ) ), `Label(`opt(`outputField), text), `PushButton("&OK") ) ) ); UI::UserInput(); UI::CloseDialog(); } } UI::CloseDialog(); }
{ UI::OpenDialog( `VBox( `MinSize( 25, 8, `Table(`id(`table), `opt(`notify), `header("Name", "Amount"), [ `item(`id(1), "Chili", 0), `item(`id(2), "Salami Baguette", 0), `item(`id(3), "Spaghetti", 0), `item(`id(4), "Steak Sandwich", 0) ] ) ), `Label("Double-click any item to increase the number"), `Right( `PushButton(`id(`cancel), "&Close") ) ) ); while ( UI::UserInput() != `cancel) { integer current_item_id = (integer) UI::QueryWidget(`id(`table), `CurrentItem); integer amount = tointeger( (string) UI::QueryWidget(`table, `Cell( current_item_id, 1 ) ) ); amount = amount+1; y2debug( "amount: %1", amount ); UI::ChangeWidget(`id(`table), `Cell( current_item_id, 1 ), amount ); } UI::CloseDialog(); }