-
Notifications
You must be signed in to change notification settings - Fork 6
/
table_paged.go
121 lines (109 loc) · 4.17 KB
/
table_paged.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
package control
import (
"context"
"github.com/goradd/goradd/pkg/page"
"github.com/goradd/goradd/pkg/page/action"
"github.com/goradd/goradd/pkg/page/control/data"
)
type PagedTableI interface {
TableEmbedder
PagedControlI
}
type PagedTable struct {
Table
PagedControl
}
func NewPagedTable(parent page.ControlI, id string) *PagedTable {
t := &PagedTable{}
t.Init(t, parent, id)
return t
}
func (t *PagedTable) Init(self page.ControlI, parent page.ControlI, id string) {
t.Table.Init(self, parent, id)
t.PagedControl.SetPageSize(0) // use the application default
}
// PagedTableCreator creates a table that can be paged
type PagedTableCreator struct {
// ID is the control id
ID string
// HasColTags will make the table render <col> tags
HasColTags bool
// Caption is the content of the caption tag, and can either be a string, or a data pager
Caption interface{}
// HideIfEmpty will hide the table completely if it has no data. Otherwise, the table and headers will be shown, but no data rows
HideIfEmpty bool
// HeaderRowCount is the number of header rows. You must set this to at least 1 to show header rows.
HeaderRowCount int
// FooterRowCount is the number of footer rows.
FooterRowCount int
// RowStyler returns the attributes to be used in a cell.
RowStyler TableRowAttributer
// RowStylerID is a control id for the control that will be the RowStyler of the table.
RowStylerID string
// HeaderRowStyler returns the attributes to be used in a header cell.
HeaderRowStyler TableHeaderRowAttributer
// HeaderRowStylerID is a control id for the control that will be the HeaderRowStyler of the table.
HeaderRowStylerID string
// FooterRowStyler returns the attributes to be used in a footer cell. It can be either a control id or a TableFooterRowAttributer.
FooterRowStyler TableFooterRowAttributer
// FooterRowStylerID is a control id for the control that will be the FooterRowStyler of the table.
FooterRowStylerID string
// Columns are the column creators that will add columns to the table
Columns []ColumnCreator
// DataProvider is the data binder for the table. It can be either a control id or a DataBinder
DataProvider data.DataBinder
// DataProviderID is the control id of the data binder for the table.
DataProviderID string
// Data is the actual data for the table, and should be a slice of objects
Data interface{}
// Sortable will make the table sortable
Sortable bool
// SortHistoryLimit will set how many columns deep we will remember the sorting for multi-level sorts
SortHistoryLimit int
OnCellClick action.CallbackActionI
page.ControlOptions
// PageSize is the number of rows to include in a page
PageSize int
// SaveState will cause the table to remember what page it was on
SaveState bool
}
// Create is called by the framework to create a new control from the Creator. You
// do not normally need to call this.
func (c PagedTableCreator) Create(ctx context.Context, parent page.ControlI) page.ControlI {
ctrl := NewPagedTable(parent, c.ID)
c.Init(ctx, ctrl)
return ctrl
}
// Init is called by implementations of Buttons to initialize a control with the
// creator. You do not normally need to call this.
func (c PagedTableCreator) Init(ctx context.Context, ctrl PagedTableI) {
sub := TableCreator {
ID: c.ID,
HasColTags: c.HasColTags,
Caption: c.Caption,
HideIfEmpty: c.HideIfEmpty,
HeaderRowCount: c.HeaderRowCount,
FooterRowCount: c.FooterRowCount,
RowStyler: c.RowStyler,
HeaderRowStyler: c.HeaderRowStyler,
FooterRowStyler: c.FooterRowStyler,
Columns: c.Columns,
DataProvider: c.DataProvider,
Data: c.Data,
Sortable: c.Sortable,
SortHistoryLimit: c.SortHistoryLimit,
OnCellClick: c.OnCellClick,
ControlOptions: c.ControlOptions,
}
sub.Init(ctx, ctrl)
if c.PageSize != 0 {
ctrl.SetPageSize(c.PageSize)
}
if c.SaveState {
ctrl.SaveState(ctx, true)
}
}
// GetPagedTable is a convenience method to return the table with the given id from the page.
func GetPagedTable(c page.ControlI, id string) *PagedTable {
return c.Page().GetControl(id).(*PagedTable)
}