]> saetta.ns0.it Git - zakgrid_go/commitdiff
Taking into account cols not in db.
authorAndrea Zagli <azagli@libero.it>
Sun, 22 Aug 2021 06:27:32 +0000 (08:27 +0200)
committerAndrea Zagli <azagli@libero.it>
Sun, 22 Aug 2021 06:27:32 +0000 (08:27 +0200)
main.go

diff --git a/main.go b/main.go
index 83bf1ed1cb55fb56b99246bd648a2c82159aaf50..e4de04c9701fdbfa41e644104822c3224621bb8c 100644 (file)
--- a/main.go
+++ b/main.go
@@ -38,7 +38,12 @@ func (g *grid) getRowFromDb (m map[string]interface{}) string {
        ret := "<tr>\n"
 
        for _, c := range g.cols {
-               ret += fmt.Sprintf("\t<td>%v</td>\n", m[c.name])
+               v, ok := m[c.name]
+               if ok {
+                       ret += fmt.Sprintf("\t<td>%v</td>\n", v)
+               } else {
+                       ret += fmt.Sprintf("\t<td></td>\n")
+               }
        }
 
        ret += "</tr>\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()