diff --git a/table/command.go b/table/command.go index 08dc725ab..ae52bbf91 100644 --- a/table/command.go +++ b/table/command.go @@ -87,11 +87,17 @@ func (o Options) Run() error { } rows := make([]table.Row, 0, len(data)) - for _, row := range data { - if len(row) > len(columns) { + for row := range data { + if len(data[row]) > len(columns) { return fmt.Errorf("invalid number of columns") } - for i, col := range row { + + // fixes the data in case we have more columns than rows: + for len(data[row]) < len(columns) { + data[row] = append(data[row], "") + } + + for i, col := range data[row] { if len(o.Widths) == 0 { width := lipgloss.Width(col) if width > columns[i].Width { @@ -99,7 +105,8 @@ func (o Options) Run() error { } } } - rows = append(rows, table.Row(row)) + + rows = append(rows, table.Row(data[row])) } if o.Print {