Data-driven tables

Go back


ITGlobal CLI offers a way to generate a pretty-formatted tables from a list of objects.

Quickstart

  1. First, prepare source data:

    var list = new List<TableRow>();
    // TableRow here is a custom type
    
    // TODO fill list with table source data
    
  2. Then create a strongly-typed table builder:

    // Create and configure table renderer
    var renderer = TableRenderer.Grid(GridTableStyle.Pretty());
    
    // Then create a table builder attached to source data and renderer
    var table = TerminalTable.Create(list, renderer);
    // or alternatively create a table builder with default renderer
    var table = TerminalTable.Create(list);
    
  3. Define table columns:

    table.Column("ID", _ => _.Id, align: _ => TableCellAlignment.Left);
    table.Column("Image", _ => _.Image);
    table.Column("Created", _ => _.Created);
    table.Column("Status", _ => _.Status, style: _ => _.IsRunning ? ColoredStringStyle.Red : null);
    
  4. And finally render table to console:

    table.Draw();
    

    example-data-driven

Column parameters

For every column you you may define the following parameters:

Note that both header text and body cell text are AnsiStrings, not an ordinary string. Thus you may use any custom colorization in them.

Table parameters

There are few method to define table-wide parameters: