-
Notifications
You must be signed in to change notification settings - Fork 6
/
repeater.go
59 lines (52 loc) · 1.4 KB
/
repeater.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package panels
import (
"context"
"fmt"
"github.com/goradd/goradd/pkg/page"
. "github.com/goradd/goradd/pkg/page/control"
"io"
)
type RepeaterPanel struct {
Panel
}
func NewRepeaterPanel(ctx context.Context, parent page.ControlI) {
p := new(RepeaterPanel)
p.Init(p, ctx, parent, "repeaterPanel")
}
func (p *RepeaterPanel) Init(self any, ctx context.Context, parent page.ControlI, id string) {
p.Panel.Init(self, parent, id)
p.AddControls(ctx,
RepeaterCreator{
ID: "repeater1",
ItemHtmler: p,
DataProvider: p,
PageSize: 5,
},
// A DataPager can be a standalone control, which you draw manually
DataPagerCreator{
ID: "pager1",
PagedControlID: "repeater1",
},
)
}
// BindData satisfies the data provider interface so that the parent panel of the table
// is the one that is providing the table.
func (p *RepeaterPanel) BindData(ctx context.Context, s DataManagerI) {
switch s.ID() {
case "repeater1":
t := s.(PagedControlI)
t.SetTotalItems(uint(len(tableMapData)))
start, end := t.SliceOffsets()
s.SetData(tableMapData[start:end])
}
}
func (p *RepeaterPanel) RepeaterHtml(ctx context.Context, r RepeaterI, i int, data interface{}, w io.Writer) {
d := data.(TableMapData)
if _, err := fmt.Fprintf(w, `<div>ID: %s, Name: %s</div>`, d["id"], d["name"]); err != nil {
panic(err)
}
return
}
func init() {
page.RegisterControl(&RepeaterPanel{})
}