You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
| Fixed row count per page |`WithPageSize(n)` — auto footer shows `current/total`|
59
+
| Fixed terminal-line height |`WithTargetHeight(n)` — rows per page calculated from actual rendered height; footer shown only when multi-page |
60
+
| Truly fixed height (never grows or shrinks) |`WithTargetHeight(n).WithMinimumHeight(n)` — `WithTargetHeight` caps the top, `WithMinimumHeight` pads the bottom when rows don't fill the page |
61
+
| Custom footer text |`WithStaticFooter(text)` — replaces the auto page-count footer |
62
+
| Hide footer |`WithFooterVisibility(false)`|
63
+
64
+
`WithPageSize` and `WithTargetHeight` are mutually exclusive. Prefer
65
+
`WithTargetHeight` when `WithMultiline` is enabled, since it pages by actual
66
+
rendered line count rather than row count.
67
+
[See the pagination example](examples/pagination) and
68
+
[the targetheight example](examples/targetheight) for demonstrations.
56
69
57
70
Built-in filtering can be enabled by setting any columns as filterable, using
58
71
a text box in the footer and `/` (customizable by keybind) to start filtering.
72
+
[See the filter example](examples/filter).
59
73
60
74
A missing indicator can be supplied to show missing data in rows.
61
75
62
-
Columns can be sorted in either ascending or descending order. Multiple columns
63
-
can be specified in a row. If multiple columns are specified, first the table
76
+
Columns can be sorted in either ascending or descending order. Multiple columns
77
+
can be specified in a row. If multiple columns are specified, first the table
64
78
is sorted by the first specified column, then each group within that column is
65
-
sorted in smaller and smaller groups. [See the sorting example](examples/sorting)
66
-
for more information. If a column contains numbers (either ints or floats),
67
-
the numbers will be sorted by numeric value. Otherwise rendered string values
79
+
sorted in smaller and smaller groups. [See the sorting example](examples/sorting)
80
+
for more information. If a column contains numbers (either ints or floats),
81
+
the numbers will be sorted by numeric value. Otherwise rendered string values
68
82
will be compared.
69
83
70
84
If a feature is confusing to use or could use a better example, please feel free
@@ -73,20 +87,20 @@ to open an issue.
73
87
## Defining table data
74
88
75
89
A table is defined by a list of `Column` values that define the columns in the
76
-
table. Each `Column` is associated with a unique string key.
90
+
table. Each `Column` is associated with a unique string key.
77
91
78
-
A table contains a list of `Row`s. Each `Row` contains a `RowData` object which
92
+
A table contains a list of `Row`s. Each `Row` contains a `RowData` object which
79
93
is simply a map of string column IDs to arbitrary `any` data values.
80
-
When the table is rendered, each `Row` is checked for each `Column` key. If the
94
+
When the table is rendered, each `Row` is checked for each `Column` key. If the
81
95
key exists in the `Row`'s `RowData`, it is rendered with `fmt.Sprintf("%v")`.
82
96
If it does not exist, nothing is rendered.
83
97
84
-
Extra data in the `RowData` object is ignored. This can be helpful to simply
98
+
Extra data in the `RowData` object is ignored. This can be helpful to simply
85
99
dump data into `RowData` and create columns that select what is interesting to
86
100
view, or to generate different columns based on view options on the fly (see the
87
101
[metadata example](./examples/metadata) for an example of using this).
88
102
89
-
An example is given below. For more detailed examples, see
103
+
An example is given below. For more detailed examples, see
90
104
[the examples directory](./examples).
91
105
92
106
```golang
@@ -147,8 +161,8 @@ rows := []table.Row{
147
161
### A note on 'metadata'
148
162
149
163
There may be cases where you wish to reference some kind of data object in the
150
-
table. For example, a table of users may display a user name, ID, etc., and you
151
-
may wish to retrieve data about the user when the row is selected. This can be
164
+
table. For example, a table of users may display a user name, ID, etc., and you
165
+
may wish to retrieve data about the user when the row is selected. This can be
152
166
accomplished by attaching hidden 'metadata' to the row in the same way as any
153
167
other data.
154
168
@@ -188,9 +202,9 @@ For a more detailed demonstration of this idea in action, please see the
188
202
189
203
## Demos
190
204
191
-
Code examples are located in [the examples directory](./examples). Run commands
205
+
Code examples are located in [the examples directory](./examples). Run commands
192
206
are added to the [Makefile](Makefile) for convenience but they should be as
193
-
simple as `go run ./examples/features/main.go`, etc. You can also view what
207
+
simple as `go run ./examples/features/main.go`, etc. You can also view what
194
208
they look like by checking the example's directory in each README here on
// The height we want the table to occupy, including borders/header/footer.
19
+
targetHeight=12
20
+
columnWidth=30
21
+
)
22
+
23
+
// The first few rows have short Pokédex entries (single-line rows); the remainder
24
+
// have longer entries that wrap to multiple lines, demonstrating that WithTargetHeight
25
+
// keeps the table height consistent regardless of row content.
26
+
varpokeRows= []table.Row{
27
+
// Short descriptions — single-line rows
28
+
table.NewRow(table.RowData{columnKeyID: 1, columnKeyName: "Bulbasaur", columnKeyDescription: "A strange seed was planted on its back at birth."}),
29
+
table.NewRow(table.RowData{columnKeyID: 4, columnKeyName: "Charmander", columnKeyDescription: "The flame on its tail shows its life force."}),
30
+
table.NewRow(table.RowData{columnKeyID: 7, columnKeyName: "Squirtle", columnKeyDescription: "Shoots water at prey while in the water."}),
31
+
table.NewRow(table.RowData{columnKeyID: 25, columnKeyName: "Pikachu", columnKeyDescription: "Has electric sacs on each cheek."}),
32
+
table.NewRow(table.RowData{columnKeyID: 39, columnKeyName: "Jigglypuff", columnKeyDescription: "Uses its round eyes to entrance foes."}),
33
+
// Longer Pokédex entries — wrap to multiple lines
34
+
table.NewRow(table.RowData{columnKeyID: 143, columnKeyName: "Snorlax", columnKeyDescription: "Very lazy. It just eats and sleeps. As its rotund bulk builds, it becomes steadily more slothful."}),
35
+
table.NewRow(table.RowData{columnKeyID: 131, columnKeyName: "Lapras", columnKeyDescription: "A gentle soul that can read the hearts of people. It can ferry people across the sea on its back."}),
36
+
table.NewRow(table.RowData{columnKeyID: 147, columnKeyName: "Dratini", columnKeyDescription: "Long considered a mythical Pokémon until a fisherman landed a live specimen after hooking it."}),
37
+
table.NewRow(table.RowData{columnKeyID: 137, columnKeyName: "Porygon", columnKeyDescription: "A Pokémon that consists entirely of programming code. Capable of moving freely in cyberspace."}),
38
+
table.NewRow(table.RowData{columnKeyID: 133, columnKeyName: "Eevee", columnKeyDescription: "Its genetic code is irregular. It may mutate if it is exposed to radiation from element stones."}),
0 commit comments