Widget["Table"]
represents a table.
"Table"
Widget["Table"]
represents a table.
Details
- To use Widget["Table"], you first need to load GUIKit using Needs["GUIKit`"].
- By default, all cells are editable. All cells in Widget["DisplayOnlyTable"] are noneditable.
- By default, most data stored in tables will be strings and left-aligned within the cells. However, it is possible to store, display, and retrieve Booleans, numbers, and images within table columns with more native controls using checkboxes, right-aligned text, and icons, respectively.
- To display images, you will need to set "columnEditable" to False to avoid corrupting the original images.
- It is important that all data within a given column match either the first row's types or the "prototype" property types if specified, because tables currently do not support rendering different data types on different rows within the same column.
- The following properties are available:
-
"items" {} the contents of the table "tableHeader" Null the table header "rowSelectionAllowed" True whether each row can be selected "columnSelectionAllowed" False whether each column can be selected "columnEditable" Null whether cells in each column can be edited "columnSortable" Null whether each column can be sorted by clicking the header "prototype" Null how to format a typical row of data "model" the model that intercedes between the user interface and the data in the table
Examples
open all close allBasic Examples (1)
Needs["GUIKit`"]ref = GUIRun[
Widget["Table", {}, InitialArguments -> {2, 3}]
];GUIScreenShot[ref]Create a basic table inside a scroll view:
ref = GUIRun[
Widget["Panel", {
Widget["ScrollPane", {
"preferredSize" -> Widget["Dimension", {"width" -> 200, "height" -> 110}],
"viewportView" -> Widget["Table", {
"items" -> {{"a1", "b1", "c1"}, {"a2", "b2", "c2"}},
PropertyValue["model", Name -> "myTableModel"]
}, Name -> "myTable"]
}]
}]
]GUIScreenShot[ref]Get the entire table contents:
ref @ PropertyValue[{"myTable", "items"}]ref @ SetPropertyValue[{"myTable", "items"},
Table[ToString[{i, j}], {i, 1, 4}, {j, 1, 3}]]GUIScreenShot[ref]ref @ PropertyValue[{"myTable", "item", 2}]ref @ SetPropertyValue[{"myTable", "item", 1},
{"10", "100", "1000"}]GUIScreenShot[ref]ref @ SetPropertyValue[{"myTableModel", "columnIdentifiers"},
{"One", "Two", "Three"}]GUIScreenShot[ref]Use the "model" component to add rows:
ref @ InvokeMethod[{"myTableModel", "addRow"}, {"x", "y", "z"}]GUIScreenShot[ref]ref @ InvokeMethod[{"myTableModel", "addColumn"}, "Id", {"1", "2", "3", "4", "5"}]GUIScreenShot[ref]ref @ InvokeMethod[{"myTableModel", "removeRow"}, 0]GUIScreenShot[ref]ref @ InvokeMethod[{"myTableModel", "insertRow"}, 2, {"i", "j", "k"}]GUIScreenShot[ref]Query and change individual cells:
ref @ InvokeMethod[{"myTableModel", "getValueAt"}, 1, 1]ref @ InvokeMethod[{"myTableModel", "setValueAt"}, "Test", 1, 1]GUIScreenShot[ref]Properties & Relations (4)
Table Headers (1)
Needs["GUIKit`"]Set the "tableHeader" property to Null to suppress display of column headers:
ref = GUIRun[
Widget["Panel", {
Widget["ScrollPane", {
"preferredSize" -> Widget["Dimension", {"width" -> 200, "height" -> 80}],
"viewportView" -> Widget["Table", {
"tableHeader" -> Null,
"items" -> Script[{{"a1", "b1", "c1"}, {"a2", "b2", "c2"}}],
PropertyValue["model", Name -> "myTableModel"]
}, Name -> "myTable"]
}]
}]
]GUIScreenShot[ref]Editability (1)
Needs["GUIKit`"]Always set "columnEditable" to False if displaying images:
ref = GUIRun[
Widget["Panel", {
Widget["ScrollPane", {
"preferredSize" -> Widget["Dimension", {"width" -> 200, "height" -> 110}],
"viewportView" -> Widget["Table", {
"columnEditable" -> {False, True, True},
"items" -> {
{Widget["Icon", {"path" -> "Wolfram/Example/Play16.gif"}], True, 45.0},
{Widget["Icon", {"data" -> Script[ExportString[ToBoxes[f''[β], TraditionalForm], "GIF", "TransparentColor" -> GrayLevel[1]]]}], False, 67.9}
},
PropertyValue["model", Name -> "myTableModel"]
}, Name -> "myTable"]
}]
}]
]GUIScreenShot[ref]Allow only the Boolean checkbox column to be editable:
ref = GUIRun[
Widget["Panel", {
Widget["ScrollPane", {
"preferredSize" -> Widget["Dimension", {"width" -> 200, "height" -> 110}],
"viewportView" -> Widget["Table", {
"columnEditable" -> {True, False, False},
"items" -> {{True, "b1", 45.0}, {False, "b2", 67.9}},
PropertyValue["model", Name -> "myTableModel"]
}, Name -> "myTable"]
}]
}]
]GUIScreenShot[ref]Sorting (1)
Needs["GUIKit`"]Allow sorting of just the first two columns:
ref = GUIRun[
Widget["Panel", {
Widget["ScrollPane", {
"preferredSize" -> Widget["Dimension", {"width" -> 200, "height" -> 110}],
"viewportView" -> Widget["Table", {
"columnSortable" -> {True, True, False},
"items" -> {{"Alpha", 65, True}, {"Beta", 89, False}, {"Gamma", 40, True}},
PropertyValue["model", Name -> "myTableModel"],
SetPropertyValue[{"myTableModel", "columnIdentifiers"},
{"Name", "Value", "Display"}],
}, Name -> "myTable"]
}
]
}]
]GUIScreenShot[ref]GUIScreenShot[ref]Print the new ordering whenever the sort order is changed (useful for re-sorting externally stored data):
ref = GUIRun[
Widget["Panel", {
Widget["ScrollPane", {
"preferredSize" -> Widget["Dimension", {"width" -> 200, "height" -> 110}],
"viewportView" -> Widget["Table", {
"columnSortable" -> {True, True, False},
"items" -> {{"Alpha", 65, True}, {"Beta", 89, False}, {"Gamma", 40, True}},
PropertyValue["model", Name -> "myTableModel"],
SetPropertyValue[{"myTableModel", "columnIdentifiers"},
{"Name", "Value", "Display"}]
}, Name -> "myTable"]
}],
BindEvent[{"myTableModel", "tableSorted"},
Script[Print[ PropertyValue[{"myTableModel", "ordering"}]]
] ]
}]
]Data Types (1)
Needs["GUIKit`"]Construct a table with Booleans in the first column and numbers in the third:
ref = GUIRun[
Widget["Panel", {
Widget["ScrollPane", {
"preferredSize" -> Widget["Dimension", {"width" -> 200, "height" -> 110}],
"viewportView" -> Widget["Table", {
"items" -> {{True, "b1", 45.0}, {False, "b2", 67.9}},
PropertyValue["model", Name -> "myTableModel"]
}, Name -> "myTable"]
}]
}]
]GUIScreenShot[ref]Get the values in appropriate forms:
ref @ PropertyValue[{"myTable", "items"}] // InputFormUse the "prototype" property to override the default rendering for a data type:
ref = GUIRun[
Widget["Panel", {
Widget["ScrollPane", {
"preferredSize" -> Widget["Dimension", {"width" -> 200, "height" -> 110}],
"viewportView" -> Widget["Table", {
"prototype" -> {"a", "a", "a"},
"items" -> {{True, "b1", 45.0}, {False, "b2", 67.9}},
PropertyValue["model", Name -> "myTableModel"]
}, Name -> "myTable"]
}]
}]
]GUIScreenShot[ref]Interactive Examples (1)
Needs["GUIKit`"]Set up a binding to know when changes are made in the table:
ref = GUIRun[
Widget["Panel", {
Widget["ScrollPane", {
"preferredSize" -> Widget["Dimension", {"width" -> 300, "height" -> 60}],
"viewportView" -> Widget["Table", {
"tableHeader" -> Null,
"items" -> Script[{{"a1", "b1", "c1"}, {"a2", "b2", "c2"}}],
PropertyValue["model", Name -> "myTableModel"]
}, Name -> "myTable"]
}],
BindEvent[{"myTableModel", "tableChanged"},
Script[
Switch[PropertyValue[{"#", "type"}],
PropertyValue[{"#", "INSERT"}],
InvokeMethod[{"messageArea", "append"}, "inserted "],
PropertyValue[{"#", "UPDATE"}],
InvokeMethod[{"messageArea", "append"}, "updated "],
PropertyValue[{"#", "DELETE"}],
InvokeMethod[{"messageArea", "append"}, "deleted "]
];
InvokeMethod[{"messageArea", "append"}, "from row " <> ToString[PropertyValue[{"#", "firstRow"}] ] <>
" to row " <> ToString[PropertyValue[{"#", "lastRow"}] ] <>
" in column " <> ToString[PropertyValue[{"#", "column"}] ] <> "
"]
]],
Widget["ScrollPane", {
"viewportView" -> Widget["TextArea", {
"columns" -> 20, "rows" -> 5
}, Name -> "messageArea"]
}]
}]
]GUIScreenShot[ref]ref @ InvokeMethod[{"myTableModel", "setValueAt"}, "Test", 1, 1]ref @ InvokeMethod[{"myTableModel", "addRow"}, {"x", "y", "z"}]GUIScreenShot[ref]