Skip to content
ConsoleMonster

API Reference

Class

Table

Namespace ConsoleMonster.Widgets
Assembly ConsoleMonster
Implements

A table that negotiates its width instead of overflowing or silently dropping data: columns shrink to their minimum (wrapping, truncating at the end or in the middle, per column), then hide by ascending TableColumn.Priority with a footer that names them (+3 columns (Owner, Site, Notes)); the key column never hides. Below Table.CardsBelow cells the rows become record cards, and a single row becomes a record view. Rows can be grouped with subtotals, followed by a totals row, and limited to the top N with a Showing 50 of 1,234 footer. Raw values are formatted by the column presenters. Table.For makes a Table whose columns are read from typed items.

Inheritance

  • Object
  • Table

Constructors

public Table() #

Methods

AddColumn 2 overloads
public Table AddColumn(String header, HorizontalAlignment? alignment = null) #
Returns: Table

Adds a column.

Parameters

header System.String requiredposition: 0
The header (markup).
alignment ConsoleMonster.Layout.HorizontalAlignment? = null optionalposition: 1
Alignment, or null for automatic.

Returns

This instance.

public Table AddColumn(TableColumn column) #
Returns: Table

Adds a column definition.

Parameters

column ConsoleMonster.Widgets.TableColumn requiredposition: 0
The column.

Returns

This instance.

public Table AddGroup(String title) #
Returns: Table

Starts a group: rows added after this belong to it until the next group.

Parameters

title System.String requiredposition: 0
The group heading (markup).

Returns

This instance.

public Table AddPlainRow(params String?[] values) #
Returns: Table

Adds a row of plain text values (brackets are shown literally).

Parameters

values System.String?[] requiredposition: 0
The values.

Returns

This instance.

public Table AddRow(params TableCell[] cells) #
Returns: Table

Adds a row of cells (strings convert to markup cells). Missing cells are blank.

Parameters

cells ConsoleMonster.Widgets.TableCell[] requiredposition: 0
The cells.

Returns

This instance.

public Table AddValues(params Object?[] values) #
Returns: Table

Adds a row of raw values, formatted by the column presenters and summarised by their aggregates.

Parameters

values System.Object?[] requiredposition: 0
The values.

Returns

This instance.

public Void ClearRows() #
Returns: Void

Removes every row (columns, options and remembered column widths stay), so the table can be refilled.

public static Table<T?> For<T>(IEnumerable<T?> items) #
Returns: Table<T?>

Makes a table from typed items. Add columns with Table.Column (the header comes from the expression: s => s.Name is "Name"); without any, every public property of T is a column. Rows are read from the items when the table is laid out.

Type Parameters

T
The item type.

Parameters

items System.Collections.Generic.IEnumerable<T?> requiredposition: 0
The items.

Returns

The table.

public Size Measure(Constraints constraints, RenderContext context) #
Returns: Size

Returns the size the widget wants within the constraints.

Parameters

constraints ConsoleMonster.Layout.Constraints requiredposition: 0
The space offered.
context ConsoleMonster.Canvas.RenderContext requiredposition: 1
Profile, theme and glyphs.

Returns

The desired size, never larger than the constraints.

public Void Render(Region region, RenderContext context) #
Returns: Void

Renders into a region. The region may be smaller or larger than the measured size.

Parameters

region ConsoleMonster.Canvas.Region requiredposition: 0
The target region.
context ConsoleMonster.Canvas.RenderContext requiredposition: 1
Profile, theme and glyphs.
public Table SetFooter(params TableCell[] cells) #
Returns: Table

Sets a footer row (totals), separated by a line. It replaces the automatic totals row.

Parameters

cells ConsoleMonster.Widgets.TableCell[] requiredposition: 0
The cells.

Returns

This instance.

Properties

public IReadOnlyList<TableColumn> Columns { get; } #

The columns.

public IReadOnlyList<TableCell[]> Rows { get; } #

The rows.

public Boolean AutoTotals { get; set; } #

With Table.ShowTotals, also sums every column whose values are all numbers (not the key column and not identifier columns such as Id or Port) when it has no TableColumn.Aggregate of its own.

public String? Title { get; set; } #

A title shown above the table (markup).

public String? Caption { get; set; } #

A caption shown below the table (markup, muted).

public TableBorder Border { get; set; } #

The border style (default rounded).

public Boolean ShowHeader { get; set; } #

Whether the header row is shown (default true).

public Boolean HeaderSeparator { get; set; } #

Whether a separator row is drawn under the header (default true). When false the header is underlined instead, so data starts on the row directly below it.

public Boolean Expand { get; set; } #

Whether the table fills the available width (spare width goes to the flexible column).

public Int32 CardsBelow { get; set; } #

Below this many cells of width the rows render as record cards (key column as the card title); 0 disables cards. Default 60. Cards are used only when the grid cannot fit its minimum widths; they also take over when hiding columns would leave only the key column.

public Boolean AlwaysCards { get; set; } #

Shows the rows as record cards at any width (the Cards view of Show-Console).

public Int32 RecordViewRows { get; set; } #

A table with at most this many rows renders as a record view (default 1; 0 disables).

public Boolean ShowHiddenColumns { get; set; } #

Whether a footer names the columns hidden for lack of width (default true).

public Boolean StableWidths { get; set; } #

Whether column widths never shrink while the same table is re-rendered (live tables; default true), so columns do not jump as values change. Widths still fit the available space.

public Boolean ShowSubtotals { get; set; } #

Whether each group ends with a subtotal row for columns that have an TableColumn.Aggregate.

public Boolean ShowTotals { get; set; } #

Whether a totals row summarises all rows (columns with an TableColumn.Aggregate), unless a footer is set.

public String? TotalLabel { get; set; } #

The label of the totals row, or null (default) for the built-in word (Total in English).

public Int32 MaxRows { get; set; } #

Shows only the first N rows (0 = all) followed by Showing N of M; totals still cover every row.

public Int32? TotalRowCount { get; set; } #

The total number of records when the caller added only some of them (for example the first 50 of 1,234), so the footer can say Showing 50 of 1,234; null when every record was added.

public PresentationOptions Presentation { get; set; } #

Culture, clock and time zone for raw values.