diff --git a/table/table.go b/table/table.go index 8ad93053..1bef6717 100644 --- a/table/table.go +++ b/table/table.go @@ -85,7 +85,7 @@ func New() *Table { // ClearRows clears the table rows. func (t *Table) ClearRows() *Table { - t.data = nil + t.data = NewStringData() return t } diff --git a/table/table_test.go b/table/table_test.go index 0138d238..fbe18812 100644 --- a/table/table_test.go +++ b/table/table_test.go @@ -1140,6 +1140,24 @@ func TestTableHeightWithOffset(t *testing.T) { } } +func TestClearRows(t *testing.T) { + defer func() { + if r := recover(); r != nil { + t.Fatalf("had to recover: %v", r) + } + }() + + table := New(). + Border(lipgloss.NormalBorder()). + Headers("LANGUAGE", "FORMAL", "INFORMAL"). + Row("Chinese", "Nǐn hǎo", "Nǐ hǎo") + table.ClearRows() + table.Row("French", "Bonjour", "Salut") + + // String() will try to get the rows from table.data + table.String() +} + func debug(s string) string { return strings.ReplaceAll(s, " ", ".") }