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
CurrentItem
the ID of the currently selected item Alias: Value
Items
a list of all table items
Item(id)
read: a single item (string or term)
Item(id,column)
write: replacement for one specific cell ( see example )
A Table widget is a generalization of the SelectionBox. Information is displayed in a number of columns. Each column has a header. The number of columns and their titles are described by the first argument, which is a term with the symbol header
. For each column you add a string specifying its title. For example `header( "Name", "Price" )
creates the two columns "Name" and "Price".
The second argument is an optional list of items (rows) that are inserted in the table. Each item has the form `item( `id(
id ), first column, second column, ... )
. For each column one argument has to be specified, which must be of type void, string or integer. Strings are being left justified, integer right and a nil denote an empty cell, just as the empty string.
{ 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(); }
{ list itemlist1 = [ `item(`id(3), "Spaghetti", 8), `item(`id(4), "Steak Sandwich", 12), `item(`id(1), "Chili", 6), `item(`id(2), "Salami Baguette", nil) ]; list itemlist2 = [ `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 itemslists = [ itemlist1, itemlist2 ]; integer listnum = 0; UI::OpenDialog( `VBox( `Heading("Prices"), `MinSize( 30, 10, `Table(`id(`table), `header("Name", "price"), itemlist1) ), `Right( `HBox( `PushButton(`id(`next), "Change &Table Contents"), `PushButton(`id(`cancel), "&Close") ) ) ) ); while (UI::UserInput() != `cancel) { listnum = 1 - listnum; UI::ChangeWidget(`id(`table), `Items, select(itemslists, listnum, nil)); } 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_no = (integer) UI::QueryWidget(`id(`table), `CurrentItem); term current_item = (term) UI::QueryWidget(`table, `Item( current_item_no ) ); y2debug( "current_item: %1", current_item ); integer amount = tointeger( current_item[2]:nil ); UI::ChangeWidget(`id(`table), `Item( current_item_no, 1 ), amount+1 ); } UI::CloseDialog(); }