type missingCol func (map[string]interface{}) interface{}
-type column struct {
+type Column struct {
Name string
Title string
Align int
var rowColTmpl = "\t<td{{ if (eq .Align 1) }}align='center'{{ else if (eq .Align 2) }}align='right'{{ end }}>{{ .Value }}</td>\n"
type grid struct {
- cols []column
+ cols []Column
headerTmpl string
headerRowTmpl string
rowTmpl string
rowColTmpl string
}
-func (g *grid) addColumn (c column) {
+func (g *grid) addColumn (c Column) {
g.cols = append(g.cols, c)
}
}
func (g *grid) getRowFromMap (m map[string]interface{}) string {
+ type nc struct {
+ Column
+ Value interface{}
+ }
+
rtmpl := g.rowTmpl
if rtmpl == "" {
rtmpl = rowTmpl
}
}
- m := make(map[string]interface{})
- m["Name"] = c.Name
- m["Align"] = c.Align
- m["Value"] = v
+ nnc := nc{Column: c, Value: v}
+ fmt.Println(nnc)
var b bytes.Buffer
- err = tc.Execute(&b, m)
+ err = tc.Execute(&b, nnc)
ret += b.String()
}
g.headerTmpl = "<thead><tr>\n{{ . }}</tr></thead>\n"
- g.rowColTmpl = "\t<td data-name='{{.Name}}' {{ if (eq .Align 1) }}align='center'{{ else if (eq .Align 2) }}align='right'{{ end }}>{{ .Value }}</td>\n"
+ g.rowColTmpl = "\t<td data-name='{{.Column.Name}}' {{ if (eq .Align 1) }}align='center'{{ else if (eq .Align 2) }}align='right'{{ end }}>{{ .Value }}</td>\n"
- c := column{Name: "id", Title: "ID"}
+ c := Column{Name: "id", Title: "ID"}
g.addColumn(c)
- c = column{Name: "name", Title: "Name"}
+ c = Column{Name: "name", Title: "Name"}
g.addColumn(c)
- c = column{Name: "surname", Title: "Surname"}
+ c = Column{Name: "surname", Title: "Surname"}
g.addColumn(c)
- c = column{Name: "age", Title: "Age"}
+ c = Column{Name: "age", Title: "Age"}
g.addColumn(c)
- c = column{Name: "btn", Title: "Buttons"}
+ c = Column{Name: "btn", Title: "Buttons"}
c.toCall = missing
c.Align = 2
g.addColumn(c)