From: Andrea Zagli Date: Sun, 22 Aug 2021 06:27:32 +0000 (+0200) Subject: Taking into account cols not in db. X-Git-Url: https://saetta.ns0.it/gitweb?a=commitdiff_plain;h=0aad610bcc9f2879b5895a0e01f5726f3527b944;p=zakgrid_go Taking into account cols not in db. --- 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()