From 0aad610bcc9f2879b5895a0e01f5726f3527b944 Mon Sep 17 00:00:00 2001 From: Andrea Zagli Date: Sun, 22 Aug 2021 08:27:32 +0200 Subject: [PATCH] Taking into account cols not in db. --- main.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/main.go b/main.go index 83bf1ed..e4de04c 100644 --- a/main.go +++ b/main.go @@ -38,7 +38,12 @@ func (g *grid) getRowFromDb (m map[string]interface{}) string { ret := "\n" for _, c := range g.cols { - ret += fmt.Sprintf("\t%v\n", m[c.name]) + v, ok := m[c.name] + if ok { + ret += fmt.Sprintf("\t%v\n", v) + } else { + ret += fmt.Sprintf("\t\n") + } } ret += "\n" @@ -61,6 +66,9 @@ func main() { c = column{name: "age", title: "Age"} g.addColumn(c) + c = column{name: "btn", title: "Buttons"} + g.addColumn(c) + fmt.Println (g) header := g.getHeader() -- 2.49.0