Function Repository Resource:

GridTableForm

Source Notebook

Arrange the elements of the argument in a two-dimensional grid with row coloring that helps comprehension

Contributed by: Anton Antonov

ResourceFunction["GridTableForm"][arg]

arranges the elements of arg in a two-dimensional grid.

Details and Options

ResourceFunction["GridTableForm"] behaves like TableForm but its implementation uses Grid.
If the first argument cannot be interpreted as a two-dimensional full array, it is completed to a two-dimensional array using empty strings.
If necessary, the rows are completed with empty strings.
ResourceFunction["GridTableForm"] takes all options of Grid, along with the following additional options:
"RowBackground"{White,GrayLevel[0.96]}alternating row backgrounds
TableHeadingsAutomaticrow and column table headings
"TableHeadingsStyle"{Blue,FontFamily -> ”Times”}style applied to the table headings

Examples

Basic Examples (2) 

Here is a grid table form of a full integer array:

In[1]:=
SeedRandom[23];
ResourceFunction["GridTableForm"][RandomInteger[100, {5, 7}]]
Out[2]=

Here is a grid table form of a nested list of integers that is not a full array:

In[3]:=
ResourceFunction["GridTableForm"][
 Table[RandomInteger[100, i], {i, 3, 7}]]
Out[3]=

Scope (4) 

Table headings can be specified:

In[4]:=
ResourceFunction["GridTableForm"][RandomInteger[100, {5, 7}], TableHeadings -> {RandomWord[5], RandomWord[7]}]
Out[4]=

If needed, various completions of the data and table headings are made in order to produce the final tabular form:

In[5]:=
ResourceFunction["GridTableForm"][
 Table[RandomInteger[100, i], {i, 3, 7}], TableHeadings -> {RandomWord[3], RandomWord[3]}]
Out[5]=

GridTableForm can be invoked over Dataset objects; if the dataset has column names, then they are used as table headings:

In[6]:=
dsRand = \!\(\*
TagBox[
StyleBox[
TagBox[
TagBox[
DynamicModuleBox[{
         TypeSystem`NestedGrid`PackagePrivate`$state$$ = <|"InitialData" -> {<|"kind" -> -5.819852270098394, "unpaired" -> 6.608417593499134, "preliminary" -> "communicable", "angelically" -> -2.272987994547236|>, <|"kind" -> 0.8536608474342557, "unpaired" -> 9.533798001552185, "preliminary" -> "self-centered", "angelically" -> 0.268359528465286|>, <|"kind" -> 5.349297322544189, "unpaired" -> 6.771847645171391, "preliminary" -> "lychgate", "angelically" -> -9.564566954871797|>}, "AllowEmbedding" -> True, "InitialShape" -> TypeSystem`PackageScope`HeaderShape[<|{All, "kind"} -> 1, {All, "unpaired"} -> 1, {All, "preliminary"} -> 1, {All, "angelically"} -> 1|>, 
TypeSystem`PackageScope`Limited[
TypeSystem`PackageScope`ColumnShape[
TypeSystem`PackageScope`Limited[
TypeSystem`PackageScope`RowShape[<|"kind" -> TypeSystem`PackageScope`AtomShape[60], "unpaired" -> TypeSystem`PackageScope`AtomShape[60], "preliminary" -> TypeSystem`PackageScope`AtomShape[
                  145.60000000000002`], "angelically" -> TypeSystem`PackageScope`AtomShape[
                  60]|>], 
DirectedInfinity[1], 4, {All}]], 3, 
DirectedInfinity[1], {}]], "InitialType" -> TypeSystem`Vector[
TypeSystem`Struct[{"kind", "unpaired", "preliminary", "angelically"}, {
TypeSystem`Atom[Real], 
TypeSystem`Atom[Real], 
TypeSystem`Atom[String], 
TypeSystem`Atom[Real]}], 3], "Meta" -> <||>, "RowTarget" -> 20, "ColumnTarget" -> 10, "Shape" -> TypeSystem`PackageScope`HeaderShape[<|{All, "kind"} -> 1, {All, "unpaired"} -> 1, {All, "preliminary"} -> 1, {All, "angelically"} -> 1|>, 
TypeSystem`PackageScope`Limited[
TypeSystem`PackageScope`ColumnShape[
TypeSystem`PackageScope`Limited[
TypeSystem`PackageScope`RowShape[<|"kind" -> TypeSystem`PackageScope`AtomShape[60], "unpaired" -> TypeSystem`PackageScope`AtomShape[60], "preliminary" -> TypeSystem`PackageScope`AtomShape[
                  145.60000000000002`], "angelically" -> TypeSystem`PackageScope`AtomShape[
                  60]|>], 
DirectedInfinity[1], 4, {All}]], 3, 
DirectedInfinity[1], {}]], "Type" -> TypeSystem`Vector[
TypeSystem`Struct[{"kind", "unpaired", "preliminary", "angelically"}, {
TypeSystem`Atom[Real], 
TypeSystem`Atom[Real], 
TypeSystem`Atom[String], 
TypeSystem`Atom[Real]}], 3], "Path" -> {}, "DisplayedRowCount" -> 3, "DisplayedColumnCount" -> 4, "DataRowCount" -> 3, "DataColumnCount" -> 4, "SortPaths" -> {}, "SortDirections" -> {},
           "HiddenItemsMap" -> Null, "UpdateType" -> 1|>, TypeSystem`NestedGrid`PackagePrivate`$outputID$$, TypeSystem`NestedGrid`PackagePrivate`$path$$ = {}, TypeSystem`NestedGrid`PackagePrivate`$vPos$$ = 1, TypeSystem`NestedGrid`PackagePrivate`$hPos$$ = 1, TypeSystem`NestedGrid`PackagePrivate`$grid$$ = DynamicModule[{TypeSystem`NestedGrid`PackagePrivate`renderedGrid = Deploy[
Style[
Grid[{{
Item[
Pane[
Annotation[
EventHandler[
MouseAppearance[
Mouseover["kind", 
Style["kind", FontColor -> RGBColor[
                    0.27450980392156865`, 0.5372549019607843, 0.792156862745098]]], "LinkHand"], {"MouseClicked", 1} :> If[
TypeSystem`NestedGrid`PackagePrivate`checkInteractivity[
                    TypeSystem`NestedGrid`PackagePrivate`$state$$], 
TypeSystem`NestedGrid`PackagePrivate`updateState[
                    TypeSystem`NestedGrid`PackagePrivate`$state$$, TypeSystem`NestedGrid`PackagePrivate`$path$$, TypeSystem`NestedGrid`PackagePrivate`$vPos$$, TypeSystem`NestedGrid`PackagePrivate`$hPos$$, TypeSystem`NestedGrid`PackagePrivate`$grid$$, 
TypeSystem`NestedGrid`PackagePrivate`localHold[
TypeSystem`NestedGrid`PackagePrivate`localHold[
                    TypeSystem`NestedGrid`PackagePrivate`$outputID$$]]][{All, "kind"}, 1]]], 
TypeSystem`NestedGrid`PackagePrivate`$SliceMarker[
TypeSystem`NestedGrid`PackagePrivate`localHold[
                    TypeSystem`NestedGrid`PackagePrivate`$outputID$$]][{All, "kind"}, "ColumnHeader", True], "Mouse"], ImageSize -> {{1, Full}, Automatic}, ImageMargins -> {{5, 3}, {4, 5}}], Background -> GrayLevel[0.95], Alignment -> {Left, Baseline}], 
Item[
Pane[
Annotation[
EventHandler[
MouseAppearance[
Mouseover["unpaired", 
Style["unpaired", FontColor -> RGBColor[
                    0.27450980392156865`, 0.5372549019607843, 0.792156862745098]]], "LinkHand"], {"MouseClicked", 1} :> If[
TypeSystem`NestedGrid`PackagePrivate`checkInteractivity[
                    TypeSystem`NestedGrid`PackagePrivate`$state$$], 
TypeSystem`NestedGrid`PackagePrivate`updateState[
                    TypeSystem`NestedGrid`PackagePrivate`$state$$, TypeSystem`NestedGrid`PackagePrivate`$path$$, TypeSystem`NestedGrid`PackagePrivate`$vPos$$, TypeSystem`NestedGrid`PackagePrivate`$hPos$$, TypeSystem`NestedGrid`PackagePrivate`$grid$$, 
TypeSystem`NestedGrid`PackagePrivate`localHold[
TypeSystem`NestedGrid`PackagePrivate`localHold[
                    TypeSystem`NestedGrid`PackagePrivate`$outputID$$]]][{All, "unpaired"}, 1]]], 
TypeSystem`NestedGrid`PackagePrivate`$SliceMarker[
TypeSystem`NestedGrid`PackagePrivate`localHold[
                    TypeSystem`NestedGrid`PackagePrivate`$outputID$$]][{All, "unpaired"}, "ColumnHeader", True], "Mouse"], ImageSize -> {{1, Full}, Automatic}, ImageMargins -> {{5, 3}, {4, 5}}], Background -> GrayLevel[0.95], Alignment -> {Left, Baseline}], 
Item[
Pane[
Annotation[
EventHandler[
MouseAppearance[
Mouseover["preliminary", 
Style["preliminary", FontColor -> RGBColor[
                    0.27450980392156865`, 0.5372549019607843, 0.792156862745098]]], "LinkHand"], {"MouseClicked", 1} :> If[
TypeSystem`NestedGrid`PackagePrivate`checkInteractivity[
                    TypeSystem`NestedGrid`PackagePrivate`$state$$], 
TypeSystem`NestedGrid`PackagePrivate`updateState[
                    TypeSystem`NestedGrid`PackagePrivate`$state$$, TypeSystem`NestedGrid`PackagePrivate`$path$$, TypeSystem`NestedGrid`PackagePrivate`$vPos$$, TypeSystem`NestedGrid`PackagePrivate`$hPos$$, TypeSystem`NestedGrid`PackagePrivate`$grid$$, 
TypeSystem`NestedGrid`PackagePrivate`localHold[
TypeSystem`NestedGrid`PackagePrivate`localHold[
                    TypeSystem`NestedGrid`PackagePrivate`$outputID$$]]][{All, "preliminary"}, 1]]], 
TypeSystem`NestedGrid`PackagePrivate`$SliceMarker[
TypeSystem`NestedGrid`PackagePrivate`localHold[
                    TypeSystem`NestedGrid`PackagePrivate`$outputID$$]][{All, "preliminary"}, "ColumnHeader", True], "Mouse"], ImageSize -> {{1, Full}, Automatic}, ImageMargins -> {{5, 3}, {4, 5}}], Background -> GrayLevel[0.95], Alignment -> {Left, Baseline}], 
Item[
Pane[
Annotation[
EventHandler[
MouseAppearance[
Mouseover["angelically", 
Style["angelically", FontColor -> RGBColor[
                    0.27450980392156865`, 0.5372549019607843, 0.792156862745098]]], "LinkHand"], {"MouseClicked", 1} :> If[
TypeSystem`NestedGrid`PackagePrivate`checkInteractivity[
                    TypeSystem`NestedGrid`PackagePrivate`$state$$], 
TypeSystem`NestedGrid`PackagePrivate`updateState[
                    TypeSystem`NestedGrid`PackagePrivate`$state$$, TypeSystem`NestedGrid`PackagePrivate`$path$$, TypeSystem`NestedGrid`PackagePrivate`$vPos$$, TypeSystem`NestedGrid`PackagePrivate`$hPos$$, TypeSystem`NestedGrid`PackagePrivate`$grid$$, 
TypeSystem`NestedGrid`PackagePrivate`localHold[
TypeSystem`NestedGrid`PackagePrivate`localHold[
                    TypeSystem`NestedGrid`PackagePrivate`$outputID$$]]][{All, "angelically"}, 1]]], 
TypeSystem`NestedGrid`PackagePrivate`$SliceMarker[
TypeSystem`NestedGrid`PackagePrivate`localHold[
                    TypeSystem`NestedGrid`PackagePrivate`$outputID$$]][{All, "angelically"}, "ColumnHeader", True], "Mouse"], ImageSize -> {{1, Full}, Automatic}, ImageMargins -> {{5, 3}, {4, 5}}], Background -> GrayLevel[0.95], Alignment -> {Left, Baseline}]}, {
Item[
Pane[
Annotation[
RawBoxes["-5.81985"], 
TypeSystem`NestedGrid`PackagePrivate`$SliceMarker[
TypeSystem`NestedGrid`PackagePrivate`localHold[
                    TypeSystem`NestedGrid`PackagePrivate`$outputID$$]][{1, 
Key["kind"]}, "Item", False], "Mouse"], ImageSize -> {{60, Full}, Automatic}, ImageMargins -> {{5, 3}, {4, 5}}], ItemSize -> {Full, Automatic}], 
Item[
Pane[
Annotation[
RawBoxes["6.60842"], 
TypeSystem`NestedGrid`PackagePrivate`$SliceMarker[
TypeSystem`NestedGrid`PackagePrivate`localHold[
                    TypeSystem`NestedGrid`PackagePrivate`$outputID$$]][{1, 
Key["unpaired"]}, "Item", False], "Mouse"], ImageSize -> {{60, Full}, Automatic}, ImageMargins -> {{5, 3}, {4, 5}}], ItemSize -> {Full, Automatic}], 
Item[
Pane[
Annotation["communicable", 
TypeSystem`NestedGrid`PackagePrivate`$SliceMarker[
TypeSystem`NestedGrid`PackagePrivate`localHold[
                    TypeSystem`NestedGrid`PackagePrivate`$outputID$$]][{1, 
Key["preliminary"]}, "Item", False], "Mouse"], ImageSize -> {{145.60000000000002`, Full}, Automatic}, ImageMargins -> {{5, 3}, {4, 5}}], ItemSize -> {Full, Automatic}], 
Item[
Pane[
Annotation[
RawBoxes["-2.27299"], 
TypeSystem`NestedGrid`PackagePrivate`$SliceMarker[
TypeSystem`NestedGrid`PackagePrivate`localHold[
                    TypeSystem`NestedGrid`PackagePrivate`$outputID$$]][{1, 
Key["angelically"]}, "Item", False], "Mouse"], ImageSize -> {{60, Full}, Automatic}, ImageMargins -> {{5, 3}, {4, 5}}], ItemSize -> {Full, Automatic}]}, {
Item[
Pane[
Annotation[
RawBoxes["0.853661"], 
TypeSystem`NestedGrid`PackagePrivate`$SliceMarker[
TypeSystem`NestedGrid`PackagePrivate`localHold[
                    TypeSystem`NestedGrid`PackagePrivate`$outputID$$]][{2, 
Key["kind"]}, "Item", False], "Mouse"], ImageSize -> {{60, Full}, Automatic}, ImageMargins -> {{5, 3}, {4, 5}}], ItemSize -> {Full, Automatic}], 
Item[
Pane[
Annotation[
RawBoxes["9.5338"], 
TypeSystem`NestedGrid`PackagePrivate`$SliceMarker[
TypeSystem`NestedGrid`PackagePrivate`localHold[
                    TypeSystem`NestedGrid`PackagePrivate`$outputID$$]][{2, 
Key["unpaired"]}, "Item", False], "Mouse"], ImageSize -> {{60, Full}, Automatic}, ImageMargins -> {{5, 3}, {4, 5}}], ItemSize -> {Full, Automatic}], 
Item[
Pane[
Annotation["self-centered", 
TypeSystem`NestedGrid`PackagePrivate`$SliceMarker[
TypeSystem`NestedGrid`PackagePrivate`localHold[
                    TypeSystem`NestedGrid`PackagePrivate`$outputID$$]][{2, 
Key["preliminary"]}, "Item", False], "Mouse"], ImageSize -> {{145.60000000000002`, Full}, Automatic}, ImageMargins -> {{5, 3}, {4, 5}}], ItemSize -> {Full, Automatic}], 
Item[
Pane[
Annotation[
RawBoxes["0.26836"], 
TypeSystem`NestedGrid`PackagePrivate`$SliceMarker[
TypeSystem`NestedGrid`PackagePrivate`localHold[
                    TypeSystem`NestedGrid`PackagePrivate`$outputID$$]][{2, 
Key["angelically"]}, "Item", False], "Mouse"], ImageSize -> {{60, Full}, Automatic}, ImageMargins -> {{5, 3}, {4, 5}}], ItemSize -> {Full, Automatic}]}, {
Item[
Pane[
Annotation[
RawBoxes["5.3493"], 
TypeSystem`NestedGrid`PackagePrivate`$SliceMarker[
TypeSystem`NestedGrid`PackagePrivate`localHold[
                    TypeSystem`NestedGrid`PackagePrivate`$outputID$$]][{3, 
Key["kind"]}, "Item", False], "Mouse"], ImageSize -> {{60, Full}, Automatic}, ImageMargins -> {{5, 3}, {4, 5}}], ItemSize -> {Full, Automatic}], 
Item[
Pane[
Annotation[
RawBoxes["6.77185"], 
TypeSystem`NestedGrid`PackagePrivate`$SliceMarker[
TypeSystem`NestedGrid`PackagePrivate`localHold[
                    TypeSystem`NestedGrid`PackagePrivate`$outputID$$]][{3, 
Key["unpaired"]}, "Item", False], "Mouse"], ImageSize -> {{60, Full}, Automatic}, ImageMargins -> {{5, 3}, {4, 5}}], ItemSize -> {Full, Automatic}], 
Item[
Pane[
Annotation["lychgate", 
TypeSystem`NestedGrid`PackagePrivate`$SliceMarker[
TypeSystem`NestedGrid`PackagePrivate`localHold[
                    TypeSystem`NestedGrid`PackagePrivate`$outputID$$]][{3, 
Key["preliminary"]}, "Item", False], "Mouse"], ImageSize -> {{145.60000000000002`, Full}, Automatic}, ImageMargins -> {{5, 3}, {4, 5}}], ItemSize -> {Full, Automatic}], 
Item[
Pane[
Annotation[
RawBoxes["-9.56457"], 
TypeSystem`NestedGrid`PackagePrivate`$SliceMarker[
TypeSystem`NestedGrid`PackagePrivate`localHold[
                    TypeSystem`NestedGrid`PackagePrivate`$outputID$$]][{3, 
Key["angelically"]}, "Item", False], "Mouse"], ImageSize -> {{60, Full}, Automatic}, ImageMargins -> {{5, 3}, {4, 5}}], ItemSize -> {Full, Automatic}]}}, BaseStyle -> {ContextMenu -> Dynamic[
                  TypeSystem`NestedGrid`PackagePrivate`$contextMenuTrigger; Which[
                    TypeSystem`NestedGrid`PackagePrivate`$lastOutputID =!= TypeSystem`NestedGrid`PackagePrivate`localHold[
                    TypeSystem`NestedGrid`PackagePrivate`$outputID$$], {}, TypeSystem`NestedGrid`PackagePrivate`$contextMenuTrigger === TypeSystem`NestedGrid`PackagePrivate`$lastContextMenuTrigger, TypeSystem`NestedGrid`PackagePrivate`$lastContextMenu, True, TypeSystem`NestedGrid`PackagePrivate`$lastContextMenuTrigger = TypeSystem`NestedGrid`PackagePrivate`$contextMenuTrigger; TypeSystem`NestedGrid`PackagePrivate`$lastContextMenu = Block[{TypeSystem`NestedGrid`PackagePrivate`$globalScrollPos = {TypeSystem`NestedGrid`PackagePrivate`$vPos$$, TypeSystem`NestedGrid`PackagePrivate`$hPos$$}}, 
With[{TypeSystem`NestedGrid`PackagePrivate`lastPath$ = TypeSystem`NestedGrid`PackagePrivate`$lastPath, TypeSystem`NestedGrid`PackagePrivate`lastPathType$ = TypeSystem`NestedGrid`PackagePrivate`$lastPathType, TypeSystem`NestedGrid`PackagePrivate`isLeafHeader$ = TypeSystem`NestedGrid`PackagePrivate`$lastPathIsLeafHeader, TypeSystem`NestedGrid`PackagePrivate`headerHidden$ = And[
MatchQ[TypeSystem`NestedGrid`PackagePrivate`$lastPathType, 
Alternatives["RowHeader", "ColumnHeader"]], 
TypeSystem`NestedGrid`PackagePrivate`headerHiddenQ[
                    TypeSystem`NestedGrid`PackagePrivate`$lastPath, TypeSystem`NestedGrid`PackagePrivate`$state$$]], TypeSystem`NestedGrid`PackagePrivate`allHidden$ = TypeSystem`NestedGrid`PackagePrivate`allHiddenQ[
                    TypeSystem`NestedGrid`PackagePrivate`$lastPath, TypeSystem`NestedGrid`PackagePrivate`$state$$], TypeSystem`NestedGrid`PackagePrivate`anyHidden$ = TypeSystem`NestedGrid`PackagePrivate`anyHiddenQ[
                    TypeSystem`NestedGrid`PackagePrivate`$lastPath, TypeSystem`NestedGrid`PackagePrivate`$state$$], TypeSystem`NestedGrid`PackagePrivate`sortDirection$ = TypeSystem`NestedGrid`PackagePrivate`columnSortDirection[TypeSystem`NestedGrid`PackagePrivate`$lastPath, 
TypeSystem`NestedGrid`PackagePrivate`$state$$["SortPaths"], 
TypeSystem`NestedGrid`PackagePrivate`$state$$["SortDirections"]], TypeSystem`NestedGrid`PackagePrivate`haveData$ = Not[
FailureQ[
TypeSystem`NestedGrid`PackagePrivate`datasetInitialData[
                    TypeSystem`NestedGrid`PackagePrivate`$state$$]]], TypeSystem`NestedGrid`PackagePrivate`isKeyDummy$ = Not[
FreeQ[TypeSystem`NestedGrid`PackagePrivate`$lastPath, Keys]]}, 
Join[{
If[
Or[
Not[TypeSystem`NestedGrid`PackagePrivate`haveData$], 
Not[TypeSystem`NestedGrid`PackagePrivate`anyHidden$], TypeSystem`NestedGrid`PackagePrivate`isKeyDummy$],
                     Nothing, 
MenuItem["Show " <> Which[
                    TypeSystem`NestedGrid`PackagePrivate`lastPathType$ == "Item", "", TypeSystem`NestedGrid`PackagePrivate`lastPathType$ == "RowHeader", "Row", TypeSystem`NestedGrid`PackagePrivate`lastPathType$ == "ColumnHeader", "Column", True, ""], 
KernelExecute[
TypeSystem`NestedGrid`PackagePrivate`updateHiddenItems[
                    TypeSystem`NestedGrid`PackagePrivate`$state$$, TypeSystem`NestedGrid`PackagePrivate`$path$$, TypeSystem`NestedGrid`PackagePrivate`$vPos$$, TypeSystem`NestedGrid`PackagePrivate`$hPos$$, TypeSystem`NestedGrid`PackagePrivate`$grid$$, 
TypeSystem`NestedGrid`PackagePrivate`localHold[
TypeSystem`NestedGrid`PackagePrivate`localHold[
                    TypeSystem`NestedGrid`PackagePrivate`$outputID$$]]][TypeSystem`NestedGrid`PackagePrivate`lastPath$, "remove"]], MenuEvaluator -> Automatic]], 
If[
Or[
Not[TypeSystem`NestedGrid`PackagePrivate`haveData$], 
TypeSystem`NestedGrid`PackagePrivate`pathEmptyQ[
                    TypeSystem`NestedGrid`PackagePrivate`$lastPath, TypeSystem`NestedGrid`PackagePrivate`$state$$], TypeSystem`NestedGrid`PackagePrivate`isKeyDummy$, And[TypeSystem`NestedGrid`PackagePrivate`allHidden$, TypeSystem`NestedGrid`PackagePrivate`headerHidden$]], Nothing, 
MenuItem["Hide " <> Which[
                    TypeSystem`NestedGrid`PackagePrivate`lastPathType$ == "Item", "", TypeSystem`NestedGrid`PackagePrivate`lastPathType$ == "RowHeader", "Row", TypeSystem`NestedGrid`PackagePrivate`lastPathType$ == "ColumnHeader", "Column", True, ""], 
KernelExecute[
TypeSystem`NestedGrid`PackagePrivate`updateHiddenItems[
                    TypeSystem`NestedGrid`PackagePrivate`$state$$, TypeSystem`NestedGrid`PackagePrivate`$path$$, TypeSystem`NestedGrid`PackagePrivate`$vPos$$, TypeSystem`NestedGrid`PackagePrivate`$hPos$$, TypeSystem`NestedGrid`PackagePrivate`$grid$$, 
TypeSystem`NestedGrid`PackagePrivate`localHold[
TypeSystem`NestedGrid`PackagePrivate`localHold[
                    TypeSystem`NestedGrid`PackagePrivate`$outputID$$]]][TypeSystem`NestedGrid`PackagePrivate`lastPath$, "add"]], MenuEvaluator -> Automatic]], Delimiter}, 
If[
And[TypeSystem`NestedGrid`PackagePrivate`haveData$, 
MatchQ[TypeSystem`NestedGrid`PackagePrivate`lastPathType$, 
Alternatives["ColumnHeader", "KeyDummy"]], TypeSystem`NestedGrid`PackagePrivate`isLeafHeader$, 
Not[TypeSystem`NestedGrid`PackagePrivate`allHidden$]], {
If[
                    TypeSystem`NestedGrid`PackagePrivate`sortDirection$ =!= "Ascending", 
MenuItem["Sort", 
KernelExecute[
TypeSystem`NestedGrid`PackagePrivate`updateSort[
                    TypeSystem`NestedGrid`PackagePrivate`$state$$, TypeSystem`NestedGrid`PackagePrivate`$path$$, TypeSystem`NestedGrid`PackagePrivate`$vPos$$, TypeSystem`NestedGrid`PackagePrivate`$hPos$$, TypeSystem`NestedGrid`PackagePrivate`$grid$$, 
TypeSystem`NestedGrid`PackagePrivate`localHold[
                    TypeSystem`NestedGrid`PackagePrivate`$outputID$$]][TypeSystem`NestedGrid`PackagePrivate`lastPath$, "Ascending"]], MenuEvaluator -> Automatic], Nothing], 
If[TypeSystem`NestedGrid`PackagePrivate`sortDirection$ =!= "Descending", 
MenuItem["Reverse Sort", 
KernelExecute[
TypeSystem`NestedGrid`PackagePrivate`updateSort[
                    TypeSystem`NestedGrid`PackagePrivate`$state$$, TypeSystem`NestedGrid`PackagePrivate`$path$$, TypeSystem`NestedGrid`PackagePrivate`$vPos$$, TypeSystem`NestedGrid`PackagePrivate`$hPos$$, TypeSystem`NestedGrid`PackagePrivate`$grid$$, 
TypeSystem`NestedGrid`PackagePrivate`localHold[
                    TypeSystem`NestedGrid`PackagePrivate`$outputID$$]][TypeSystem`NestedGrid`PackagePrivate`lastPath$, "Descending"]], MenuEvaluator -> Automatic], Nothing], 
If[TypeSystem`NestedGrid`PackagePrivate`sortDirection$ =!= None, 
MenuItem["Unsort", 
KernelExecute[
TypeSystem`NestedGrid`PackagePrivate`updateSort[
                    TypeSystem`NestedGrid`PackagePrivate`$state$$, TypeSystem`NestedGrid`PackagePrivate`$path$$, TypeSystem`NestedGrid`PackagePrivate`$vPos$$, TypeSystem`NestedGrid`PackagePrivate`$hPos$$, TypeSystem`NestedGrid`PackagePrivate`$grid$$, 
TypeSystem`NestedGrid`PackagePrivate`localHold[
                    TypeSystem`NestedGrid`PackagePrivate`$outputID$$]][TypeSystem`NestedGrid`PackagePrivate`lastPath$, None]], MenuEvaluator -> Automatic], Nothing], Delimiter}, {}], {
MenuItem[
                    "Copy Position to Clipboard", 
KernelExecute[
TypeSystem`NestedGrid`PackagePrivate`toCurrentPosition[
                    TypeSystem`NestedGrid`PackagePrivate`copyClip]], MenuEvaluator -> Automatic], 
If[TypeSystem`NestedGrid`PackagePrivate`haveData$, 
MenuItem["Copy Data to Clipboard", 
KernelExecute[
TypeSystem`NestedGrid`PackagePrivate`toCurrentData[ TypeSystem`NestedGrid`PackagePrivate`$state$$, TypeSystem`NestedGrid`PackagePrivate`copyClip]], MenuEvaluator -> Automatic], Nothing], Delimiter, MenuItem["Paste Position in New Cell", 
KernelExecute[
TypeSystem`NestedGrid`PackagePrivate`toCurrentPosition[
                    TypeSystem`NestedGrid`PackagePrivate`cellPaste]], MenuEvaluator -> Automatic], 
If[TypeSystem`NestedGrid`PackagePrivate`haveData$, 
MenuItem["Paste Data in New Cell", 
KernelExecute[
TypeSystem`NestedGrid`PackagePrivate`toCurrentData[
                    TypeSystem`NestedGrid`PackagePrivate`$state$$, TypeSystem`NestedGrid`PackagePrivate`cellPaste]], MenuEvaluator -> Automatic], Nothing]}]]]]], FontFamily -> "Source Sans Pro", FontSize -> 14, FontWeight -> Plain}, Dividers -> All, FrameStyle -> GrayLevel[0.7490196078431373], Spacings -> {0, 0}, Alignment -> Left, BaseStyle -> {FontFamily -> "Source Sans Pro", FontSize -> 14, FontWeight -> Plain}], LineBreakWithin -> False, ContextMenu -> {}, NumberMarks -> False, ShowAutoStyles -> False]], TypeSystem`NestedGrid`PackagePrivate`initialQ = True}, 
Dynamic[
TypeSystem`NestedGrid`PackagePrivate`setupViewPath[
           TypeSystem`NestedGrid`PackagePrivate`$path$$, If[
Not[TypeSystem`NestedGrid`PackagePrivate`initialQ], 
Module[{TypeSystem`NestedGrid`PackagePrivate`tmpGrid$ = $Failed, TypeSystem`NestedGrid`PackagePrivate`tmpData$ = TypeSystem`NestedGrid`PackagePrivate`datasetData[
                 TypeSystem`NestedGrid`PackagePrivate`$state$$]}, TypeSystem`NestedGrid`PackagePrivate`tmpGrid$ = If[
FailureQ[TypeSystem`NestedGrid`PackagePrivate`tmpData$], TypeSystem`NestedGrid`PackagePrivate`renderedGrid, 
TypeSystem`NestedGrid`PackagePrivate`renderGrid[
                  TypeSystem`NestedGrid`PackagePrivate`$state$$, TypeSystem`NestedGrid`PackagePrivate`$path$$, TypeSystem`NestedGrid`PackagePrivate`$vPos$$, TypeSystem`NestedGrid`PackagePrivate`$hPos$$, TypeSystem`NestedGrid`PackagePrivate`$grid$$, 
TypeSystem`NestedGrid`PackagePrivate`localHold[
                   TypeSystem`NestedGrid`PackagePrivate`$outputID$$]][
                  TypeSystem`NestedGrid`PackagePrivate`tmpData$]]; If[
                
Not[
FailureQ[TypeSystem`NestedGrid`PackagePrivate`tmpGrid$]], TypeSystem`NestedGrid`PackagePrivate`renderedGrid = TypeSystem`NestedGrid`PackagePrivate`tmpGrid$]; Null]]; TypeSystem`NestedGrid`PackagePrivate`initialQ = False; TypeSystem`NestedGrid`PackagePrivate`$vPos$$; TypeSystem`NestedGrid`PackagePrivate`$hPos$$; If[
FailureQ[TypeSystem`NestedGrid`PackagePrivate`renderedGrid], 
TypeSystem`SparseGrid[
TypeSystem`H["(data no longer present)"]], TypeSystem`NestedGrid`PackagePrivate`renderedGrid]], TrackedSymbols :> {TypeSystem`NestedGrid`PackagePrivate`$vPos$$, TypeSystem`NestedGrid`PackagePrivate`$hPos$$}], DynamicModuleValues :> {}], TypeSystem`NestedGrid`PackagePrivate`$topBar$$ = Dynamic[
TypeSystem`NestedGrid`PackagePrivate`makeFramedBar[
TypeSystem`PackageScope`SubViewPathbar[
           TypeSystem`NestedGrid`PackagePrivate`$path$$, 
TypeSystem`NestedGrid`PackagePrivate`updateState[
            TypeSystem`NestedGrid`PackagePrivate`$state$$, TypeSystem`NestedGrid`PackagePrivate`$path$$, TypeSystem`NestedGrid`PackagePrivate`$vPos$$, TypeSystem`NestedGrid`PackagePrivate`$hPos$$, TypeSystem`NestedGrid`PackagePrivate`$grid$$, 
TypeSystem`NestedGrid`PackagePrivate`localHold[
             TypeSystem`NestedGrid`PackagePrivate`$outputID$$]]]], TrackedSymbols :> {TypeSystem`NestedGrid`PackagePrivate`$path$$}], TypeSystem`NestedGrid`PackagePrivate`$bottomBar$$ = Style[
Framed[
Dynamic[
Replace[TypeSystem`NestedGrid`PackagePrivate`mouseAnnotation$$, {TypeSystem`NestedGrid`PackagePrivate`$SliceMarker[
TypeSystem`NestedGrid`PackagePrivate`localHold[
                TypeSystem`NestedGrid`PackagePrivate`$outputID$$]][
               Null, 
Blank[]] -> "", TypeSystem`NestedGrid`PackagePrivate`$SliceMarker[
TypeSystem`NestedGrid`PackagePrivate`localHold[
                TypeSystem`NestedGrid`PackagePrivate`$outputID$$]][
Pattern[TypeSystem`NestedGrid`PackagePrivate`path$, 
Blank[]], 
Pattern[TypeSystem`NestedGrid`PackagePrivate`pathType$, 
Blank[]], 
Pattern[TypeSystem`NestedGrid`PackagePrivate`isLeafHeader$, 
Blank[]]] :> (
               Increment[
                TypeSystem`NestedGrid`PackagePrivate`$contextMenuTrigger]; TypeSystem`NestedGrid`PackagePrivate`$lastPath = TypeSystem`NestedGrid`PackagePrivate`path$; TypeSystem`NestedGrid`PackagePrivate`$lastPathType = TypeSystem`NestedGrid`PackagePrivate`pathType$; TypeSystem`NestedGrid`PackagePrivate`$lastPathIsLeafHeader = TypeSystem`NestedGrid`PackagePrivate`isLeafHeader$; TypeSystem`NestedGrid`PackagePrivate`$lastOutputID = TypeSystem`NestedGrid`PackagePrivate`localHold[
                 TypeSystem`NestedGrid`PackagePrivate`$outputID$$]; TypeSystem`NestedGrid`PackagePrivate`makePathTrail[
                TypeSystem`NestedGrid`PackagePrivate`path$, TypeSystem`NestedGrid`PackagePrivate`makePathElements]), Null :> Spacer[10], Blank[] :> Spacer[10]}], TrackedSymbols :> {TypeSystem`NestedGrid`PackagePrivate`mouseAnnotation$$}], FrameStyle -> None, ImageMargins -> 0, FrameMargins -> 0, Alignment -> Top, ImageSize -> {Automatic, 15}], FontSize -> 1], TypeSystem`NestedGrid`PackagePrivate`mouseAnnotation$$ = Null}, 
DynamicWrapperBox[
DynamicBox[ToBoxes[
Dataset`DatasetContent[
            2, "Path" -> Hold[
              TypeSystem`NestedGrid`PackagePrivate`$path$$], "Grid" -> Hold[
              TypeSystem`NestedGrid`PackagePrivate`$grid$$], "State" -> Hold[
              TypeSystem`NestedGrid`PackagePrivate`$state$$], "VPos" -> Hold[
              TypeSystem`NestedGrid`PackagePrivate`$vPos$$], "HPos" -> Hold[
              TypeSystem`NestedGrid`PackagePrivate`$hPos$$], "TopBar" -> Hold[
              TypeSystem`NestedGrid`PackagePrivate`$topBar$$], "BottomBar" -> Hold[
              TypeSystem`NestedGrid`PackagePrivate`$bottomBar$$], "OutputID" -> Hold[
TypeSystem`NestedGrid`PackagePrivate`localHold[
               TypeSystem`NestedGrid`PackagePrivate`$outputID$$]]], StandardForm],
ImageSizeCache->{361., {61.6425, 67.3575}},
TrackedSymbols:>{TypeSystem`NestedGrid`PackagePrivate`$state$$, TypeSystem`NestedGrid`PackagePrivate`$grid$$}], TypeSystem`NestedGrid`PackagePrivate`mouseAnnotation$$ = MouseAnnotation[],
ImageSizeCache->{361., {61.6425, 67.3575}}],
BaseStyle->{LineBreakWithin -> False},
DynamicModuleValues:>{},
Initialization:>(
          TypeSystem`NestedGrid`PackagePrivate`$outputID$$ = CreateUUID[]),
UnsavedVariables:>{TypeSystem`NestedGrid`PackagePrivate`$outputID$$}],
        
Deploy,
DefaultBaseStyle->"Deploy"],
Dataset`InterpretDataset[1],
Editable->False,
SelectWithContents->True,
Selectable->False],
ShowSpecialCharacters->False,
ShowStringCharacters->True,
NumberMarks->True,
"NodeID" -> 56],
FullForm]\);
In[7]:=
ResourceFunction["GridTableForm"][dsRand]
Out[7]=

Excess table headings are ignored:

In[8]:=
ResourceFunction["GridTableForm"][RandomInteger[100, {3, 3}], TableHeadings -> {RandomWord[8], RandomWord[5]}]
Out[8]=

Options (4) 

RowBackground (1) 

The following table demonstrates the effect of different row background specifications:

In[9]:=
arr = RandomInteger[100, {4, 3}];
bgs = {{None}, Automatic, LightGreen, {Nest[Lighter, Pink, 4], LightBlue}};
ResourceFunction[
 "GridTableForm"][{#, ResourceFunction["GridTableForm"][arr, "RowBackground" -> #]} & /@
   bgs, TableHeadings -> {"\"RowBackground\" value", "Grid"}, "RowBackground" -> {White, White}]
Out[10]=

TableHeadings (2) 

The following table demonstrates the effect of different table headings specifications:

In[11]:=
SeedRandom[89];
arr = RandomInteger[100, {4, 3}];
ths = {Automatic, RandomWord[Dimensions[arr][[2]]], {RandomWord[2], Automatic}, {RandomWord[Dimensions[arr][[1]]]}, {RandomWord[
     Dimensions[arr][[1]]], RandomWord[Dimensions[arr][[2]]]}};
ResourceFunction[
 "GridTableForm"][{#, ResourceFunction["GridTableForm"][arr, TableHeadings -> #]} & /@ ths, TableHeadings -> {"\"TableHeadings\" value", "Grid"}]
Out[12]=

If the row headings or column headings are too short, they are completed with SpanFromAbove and SpanFromLeft, respectively:

In[13]:=
ResourceFunction["GridTableForm"][RandomInteger[100, {5, 7}], TableHeadings -> {RandomWord[3], RandomWord[3]}]
Out[13]=

Grid options (1) 

GridTableForm takes all options of Grid:

In[14]:=
arr = RandomInteger[100, {4, 3}];
ResourceFunction["GridTableForm"][arr, "RowBackground" -> Blue, Background -> LightGreen, Dividers -> All, FrameStyle -> Directive[Red, Bold, Dotted]]
Out[7]=

Applications (3) 

Show a sample of machine learning data with corresponding variable names:

In[15]:=
arr = Flatten@*List @@@ RandomSample[ExampleData[{"MachineLearning", "Titanic"}, "Data"], 12];
header = Flatten@*List @@ ExampleData[{"MachineLearning", "Titanic"}, "VariableDescriptions"];
ResourceFunction["GridTableForm"][arr, TableHeadings -> header]
Out[16]=

When studying data arrays, the use of the ResourceFunction RecordsSummary can be completed with GridTableForm:

In[17]:=
arr = Normal[ExampleData[{"Dataset", "Titanic"}][Values]];
header = Normal[Keys[ExampleData[{"Dataset", "Titanic"}][[1]]]];
In[18]:=
ResourceFunction["RecordsSummary"][arr, header]
Out[18]=
In[19]:=
ResourceFunction["GridTableForm"][RandomSample[arr, 12], TableHeadings -> header]
Out[19]=

Show all rows and columns of a dataset:

In[20]:=
SeedRandom[32];
dsRand = ResourceFunction["RandomTabularDataset"][{25, 15}, "Generators" -> {RandomInteger, RandomReal}];
ResourceFunction["GridTableForm"][dsRand]
Out[22]=

Properties and Relations (2) 

GridTableForm is related to both TableForm and Grid. The relation with TableForm can be seen in this example:

In[23]:=
SeedRandom[14];
arr3 = RandomInteger[100, {4, 3}];
header = RandomWord[3];
In[24]:=
ResourceFunction["GridTableForm"][arr3, TableHeadings -> {Automatic, header}]
Out[24]=
In[25]:=
TableForm[arr3, TableHeadings -> {Automatic, header}]
Out[25]=

In order to produce a similar result using Grid, several data "augmentations" and option specifications have to be made:

In[26]:=
Grid[Prepend[MapThread[Prepend, {arr3, Range[Length[arr3]]}], Prepend[header, ""]], Dividers -> {{False, True}, {False, True}}]
Out[26]=

Possible Issues (3) 

If the specified table headings are styled, the specification given to the option "TableHeadingsStyle" has no effect:

In[27]:=
ResourceFunction["GridTableForm"][RandomInteger[100, {5, 7}], TableHeadings -> Map[Style[#, Red, Bold] &, RandomWord[7]], "TableHeadingsStyle" -> Black]
Out[27]=

The background is extended for the extended row names:

In[28]:=
ResourceFunction["GridTableForm"][RandomInteger[100, {5, 7}], TableHeadings -> {RandomWord[3], RandomWord[3]}]
Out[28]=

If the specified table headings value is a list with one element, that element is treated as a row names specification. Compare the following examples:

In[29]:=
arr4 = RandomInteger[100, {3, 5}];
header = RandomWord[5];
ResourceFunction["GridTableForm"][arr4, TableHeadings -> {header}]
Out[18]=
In[30]:=
ResourceFunction["GridTableForm"][arr4, TableHeadings -> header]
Out[30]=

Neat Examples (1) 

This example is similar to the "neat example" in the function page of TableForm:

In[31]:=
Style[ResourceFunction["GridTableForm"][
  Table[StirlingS2[n, k], {n, 1, 28}, {k, 1, 28}], FrameStyle -> {White}, Dividers -> None, "RowBackground" -> {White, LightBlue}], 2, Bold, Red]
Out[31]=

Publisher

Anton Antonov

Version History

  • 1.1.0 – 14 December 2021
  • 1.0.0 – 03 January 2020

Related Resources

License Information