Documentation ¶
Index ¶
- Constants
- func ApplyFormat(data interface{}, format string, timeFormat string) string
- func GetNode(c *AliasColumn) query.NodeI
- func MakeNodeSlice(columns []control.ColumnI) []query.NodeI
- type AliasColumn
- type AliasGetter
- type AliasTexter
- type CellTexter
- type CheckboxColumn
- func (col *CheckboxColumn) Action(ctx context.Context, params page.ActionParams)
- func (col *CheckboxColumn) AddActions(t page.ControlI)
- func (col *CheckboxColumn) CellText(ctx context.Context, rowNum int, colNum int, data interface{}) string
- func (col *CheckboxColumn) Changes() map[string]bool
- func (col *CheckboxColumn) CheckboxAttributes(data interface{}) *html.Attributes
- func (col *CheckboxColumn) HeaderCellHtml(ctx context.Context, rowNum int, colNum int) (h string)
- func (col *CheckboxColumn) Init()
- func (t *CheckboxColumn) MarshalState(m maps.Setter)
- func (col *CheckboxColumn) PreRender()
- func (col *CheckboxColumn) ResetChanges()
- func (col *CheckboxColumn) SetShowCheckAll(s bool) *CheckboxColumn
- func (t *CheckboxColumn) UnmarshalState(m maps.Loader)
- func (col *CheckboxColumn) UpdateFormValues(ctx *page.Context)
- type CheckboxColumnI
- type CheckboxProvider
- type CustomColumn
- type DefaultCheckboxProvider
- func (c DefaultCheckboxProvider) All() map[string]bool
- func (c DefaultCheckboxProvider) Attributes(data interface{}) *html.Attributes
- func (c DefaultCheckboxProvider) DataID() string
- func (c DefaultCheckboxProvider) IsChecked(data interface{}) bool
- func (c DefaultCheckboxProvider) RowID(data interface{}) string
- type Getter
- type GetterColumn
- type GetterTexter
- type MapColumn
- type MapTexter
- type NodeColumn
- type NodeGetter
- type NodeTexter
- type SliceColumn
- type SliceTexter
- type StringGetter
Constants ¶
const (
AllClickAction = iota + 1000
)
Variables ¶
This section is empty.
Functions ¶
func ApplyFormat ¶
ApplyFormat is used by table columns to apply the given fmt.Sprintf and time.Format strings to the data. It is exported to allow custom cell texters to use it.
func GetNode ¶ added in v0.0.7
func GetNode(c *AliasColumn) query.NodeI
func MakeNodeSlice ¶ added in v0.0.7
MakeNodeSlice is a convenience method to convert a slice of columns into a slice of nodes derived from those columns. The column slice would typically come from the table's SortColumns method, and the returned slice would be passed to the database's OrderBy clause when building a query. Since this is a common use, it will also add sort info to the nodes.
Types ¶
type AliasColumn ¶
type AliasColumn struct { control.ColumnBase // contains filtered or unexported fields }
AliasColumn is a column that uses the AliasGetter interface to get the alias text out of a database object. The data therefore should be a slice of objects that implement the AliasGetter interface. All ORM objects are AliasGetters (or should be). Call NewAliasColumn to create the column.
func NewAliasColumn ¶
func NewAliasColumn(alias string) *AliasColumn
NewAliasColumn creates a new table column that gets its text from an alias attached to an ORM object. If the alias has a Date type, you MUST call SetTimeFormat to set the format of the printed string.
func (*AliasColumn) Init ¶
func (c *AliasColumn) Init(alias string)
func (*AliasColumn) SetFormat ¶
func (c *AliasColumn) SetFormat(format string) *AliasColumn
SetFormat sets an optional format string for the column. The format string will be passed to fmt.Sprintf to further format the printed data.
func (*AliasColumn) SetTimeFormat ¶
func (c *AliasColumn) SetTimeFormat(format string) *AliasColumn
SetTimeFormat sets the time format of the string, specifically for a DateTime type.
type AliasGetter ¶
type AliasGetter interface {
GetAlias(key string) query.AliasValue
}
type AliasTexter ¶
type AliasTexter struct { // Alias is the alias name in the database object that we are interested in. Alias string // Format is a format string. It will be applied using fmt.Sprintf. If you don't provide a Format string, standard // string conversion operations will be used. Format string // TimeFormat is applied to the data using time.Format. You can have both a Format and TimeFormat, and the Format // will be applied using fmt.Sprintf after the TimeFormat is applied using time.Format. TimeFormat string }
AliasTexter gets text out of an ORM object with an alias. If the alias does not exist, it will panic.
type CellTexter ¶
type CellTexter interface { control.CellTexter }
type CheckboxColumn ¶
type CheckboxColumn struct { control.ColumnBase // contains filtered or unexported fields }
CheckboxColumn is a table column that contains a checkbox in each row. You must provide it a CheckboxProvider to connect ids and default data to the checkbox. Use Changes() to get the list of checkbox ids that have changed since the list was initially drawn.
func NewCheckboxColumn ¶
func NewCheckboxColumn(p CheckboxProvider) *CheckboxColumn
NewChecboxColumn creates a new table column that contains a checkbox. You must provide a CheckboxProvider which will connect checkbox states to data states
The table will keep track of what checkboxes have been clicked and the new values. Call Changes() to get those changes. Or, if you are recording your changes in real time, attach a CheckboxColumnClick event to the table.
func (*CheckboxColumn) Action ¶
func (col *CheckboxColumn) Action(ctx context.Context, params page.ActionParams)
Action is called by the framework to respond to an event. Here it responds to a click in the CheckAll box.
func (*CheckboxColumn) AddActions ¶
func (col *CheckboxColumn) AddActions(t page.ControlI)
AddActions adds actions to the table that the column can respond to.
func (*CheckboxColumn) CellText ¶
func (col *CheckboxColumn) CellText(ctx context.Context, rowNum int, colNum int, data interface{}) string
CellText is called by the Table drawing mechanism to draw the content of a cell, which in this case will be a checkbox.
func (*CheckboxColumn) Changes ¶
func (col *CheckboxColumn) Changes() map[string]bool
Changes returns a map of ids corresponding to checkboxes that have changed. Both true and false values indicate the current state of that particular checkbox. Note that if a user checks a box, then checks it again, even though it is back to its original value, it will still show up in the changes list.
func (*CheckboxColumn) CheckboxAttributes ¶
func (col *CheckboxColumn) CheckboxAttributes(data interface{}) *html.Attributes
CheckboxAttributes returns the attributes for the input tag that will display the checkbox. If data is nil, it indicates a checkAll box.
func (*CheckboxColumn) HeaderCellHtml ¶
HeaderCellHtml is called by the Table drawing system to draw the HeaderCellHtml.
func (*CheckboxColumn) Init ¶
func (col *CheckboxColumn) Init()
func (*CheckboxColumn) MarshalState ¶ added in v0.0.4
func (t *CheckboxColumn) MarshalState(m maps.Setter)
MarshalState is an internal function to save the state of the control
func (*CheckboxColumn) PreRender ¶ added in v0.0.4
func (col *CheckboxColumn) PreRender()
PreRender is called by the Table to tell the column that it is about to draw. Here we are resetting the list of currently showing checkboxes so that we can keep track of what is displayed. This is required to keep track of which boxes are checked in the event that Javascript is off.
func (*CheckboxColumn) ResetChanges ¶ added in v0.0.4
func (col *CheckboxColumn) ResetChanges()
ResetChanges resets the column so it is ready to accept new data. You might need to call this if you have previously called SaveState. Or, change DataID in the CheckboxProvider to cause the changes to reset.
func (*CheckboxColumn) SetShowCheckAll ¶
func (col *CheckboxColumn) SetShowCheckAll(s bool) *CheckboxColumn
SetShowCheckAll will cause the CheckAll checkbox to appear in the header. You must show at least one header row to see the checkboxes too.
func (*CheckboxColumn) UnmarshalState ¶ added in v0.0.4
func (t *CheckboxColumn) UnmarshalState(m maps.Loader)
UnmarshalState is an internal function to restore the state of the control
func (*CheckboxColumn) UpdateFormValues ¶
func (col *CheckboxColumn) UpdateFormValues(ctx *page.Context)
UpdateFormValues will look for changes to our checkboxes and record those changes.
type CheckboxColumnI ¶
type CheckboxColumnI interface { control.ColumnI CheckboxAttributes(data interface{}) *html.Attributes }
type CheckboxProvider ¶
type CheckboxProvider interface { // RowID should return a unique id corresponding to the given data item. It is used to track the checked state of an individual checkbox. RowID(data interface{}) string // IsChecked should return true if the checkbox corresponding to the row data should initially be checked. After the // initial draw, the table will keep track of the state of the checkbox, meaning you do not need to live update your data. // If you are using the table just as a selection of items to act on, just return false here. IsChecked(data interface{}) bool // Attributes returns the attributes that will be applied to the checkbox corresponding to the data row. // Use this primarily for providing custom attributes. Return nil if you have no custom attributes. Attributes(data interface{}) *html.Attributes // If you enable the checkAll box, you can use this to return a map of all the ids and their initial values here. This is // mostly helpful if your table is not showing all the rows at once (i.e. you are using a paginator or scroller and // only showing a subset of data at one time). If your table is showing a checkAll box, and you return nil here, the // checkAll will only perform a javascript checkAll, and thus only check the visible items. All() map[string]bool // DataID should return an id that identifies the overall data. This could be a database record id. // It is used to determine if the checkboxes in the column should be reset if SaveState is on. // If the DataID changes, and SaveState is on, it will reset the changes. DataID() string }
The CheckboxProvider interface defines a set of functions that you implement to provide for the initial display of a checkbox. You can descend your own CheckboxProvider from the DefaultCheckboxProvider to get the default behavior, and then add whatever functions you need to impelment.
type CustomColumn ¶
type CustomColumn struct {
control.ColumnBase
}
CustomColumn is a table column that you can customize any way you want. You simply give it a CellTexter, and return the text from the cell texter. One convenient way to use this is to define a CellText function on the parent object and pass it as the CellTexter. If your CellTexter is going to output html instead of raw text, call SetIsHtml() on the column after creating it.
func NewCustomColumn ¶
func NewCustomColumn(texter CellTexter) *CustomColumn
NewCustomColumn creates a new column with a custom cell texter.
func (*CustomColumn) Init ¶
func (c *CustomColumn) Init(texter CellTexter)
type DefaultCheckboxProvider ¶ added in v0.0.4
type DefaultCheckboxProvider struct{}
The DefaultCheckboxProvider is a mixin you can use to base your CheckboxProvider, and that will provide default functionality for the methods you don't want to implement.
func (DefaultCheckboxProvider) All ¶ added in v0.0.4
func (c DefaultCheckboxProvider) All() map[string]bool
func (DefaultCheckboxProvider) Attributes ¶ added in v0.0.4
func (c DefaultCheckboxProvider) Attributes(data interface{}) *html.Attributes
func (DefaultCheckboxProvider) DataID ¶ added in v0.0.4
func (c DefaultCheckboxProvider) DataID() string
func (DefaultCheckboxProvider) IsChecked ¶ added in v0.0.4
func (c DefaultCheckboxProvider) IsChecked(data interface{}) bool
func (DefaultCheckboxProvider) RowID ¶ added in v0.0.4
func (c DefaultCheckboxProvider) RowID(data interface{}) string
type GetterColumn ¶
type GetterColumn struct {
control.ColumnBase
}
GetterColumn is a column that uses the Getter interface to get the text out of columns. The data therefore should be a slice of objects that implement the Getter interface.
func NewGetterColumn ¶
func NewGetterColumn(index string) *GetterColumn
NewGetterColumn creates a new column that will call Get on the column to figure out what data to display. If the data is a Date, Time or DateTime type, you MUST also call SetTimeFormat. You can also optionally call SetFormat to pass it a fmt.Sprintf string to further format the data before printing.
func (*GetterColumn) Init ¶
func (c *GetterColumn) Init(index string)
func (*GetterColumn) SetFormat ¶
func (c *GetterColumn) SetFormat(format string) *GetterColumn
SetFormat sets an optional format string for the column, which will be passed to fmt.Sprintf to format the data.
func (*GetterColumn) SetTimeFormat ¶
func (c *GetterColumn) SetTimeFormat(format string) *GetterColumn
SetTimeFormat sets the format for Date, Time or DateTime type data. The format will be passed to time.Format to produce the text to print for the column.
type GetterTexter ¶
type GetterTexter struct { // Key is the key to use when calling the Get function on the object. Key string // Format is a format string. It will be applied using fmt.Sprintf. If you don't provide a Format string, standard // string conversion operations will be used. Format string // TimeFormat is applied to the data using time.Format. You can have both a Format and TimeFormat, and the Format // will be applied using fmt.Sprintf after the TimeFormat is applied using time.Format. TimeFormat string }
GetterTexter lets you get items out of map like objects using the Getter interface.
type MapColumn ¶
type MapColumn struct {
control.ColumnBase
}
MapColumn is a table that works with data that is in the form of a map. The data item itself must be convertible into a string, either by normal string conversion semantics, or using the supplied format string.
func NewMapColumn ¶
func NewMapColumn(index interface{}) *MapColumn
NewMapColumn creates a new column that will treat the data as a map. It will get the data from given index in the map and then attempt to convert it into a string. Call SetFormat to explicitly tell the column how to convert the data into a string using the fmt.Sprintf function. If the data is a Date, Time or DateTime type, you MUST call SetTimeFormat to describe the date or time format.
func (*MapColumn) SetFormat ¶
SetFormat sets an optional format string for the column, which will be passed to fmt.Sprintf to format the data.
func (*MapColumn) SetTimeFormat ¶
SetTimeFormat sets the format for Date, Time or DateTime type data. The format will be passed to time.Format to produce the text to print for the column.
type MapTexter ¶
type MapTexter struct { // Index is the index into the data that corresponds to this table Index interface{} // Format is a format string. It will be applied using fmt.Sprintf. If you don't provide a Format string, standard // string conversion operations will be used. Format string // TimeFormat is applied to the data using time.Format. You can have both a Format and TimeFormat, and the Format // will be applied using fmt.Sprintf after the TimeFormat is applied using time.Format. TimeFormat string }
MapTexter is the default CellTexter for tables. It lets you get items out of maps.
type NodeColumn ¶
type NodeColumn struct {
control.ColumnBase
}
NodeColumn is a column that uses a query.NodeI to get its text out of data that is coming from the ORM. Create it with NewNodeColumn
func NewNodeColumn ¶
func NewNodeColumn(node query.NodeI) *NodeColumn
NewNodeColumn creates a table column that uses a query.NodeI object to get its text out of an ORM object. node should point to data that is preloaded in the ORM object. If the node points to a Date, Time or DateTime type of column, you MUST specify a time format by calling SetTimeFormat.
func (*NodeColumn) GetNode ¶ added in v0.0.7
func (c *NodeColumn) GetNode() query.NodeI
func (*NodeColumn) Init ¶
func (c *NodeColumn) Init(node query.NodeI)
func (*NodeColumn) SetFormat ¶
func (c *NodeColumn) SetFormat(format string) *NodeColumn
SetFormat sets the format string of the node column.
func (*NodeColumn) SetTimeFormat ¶
func (c *NodeColumn) SetTimeFormat(format string) *NodeColumn
SetTimeFormat sets the time format of the string, specifically for a DateTime column.
type NodeGetter ¶ added in v0.0.7
type NodeTexter ¶
type NodeTexter struct { // Key is the key to use when calling the Get function on the object. Node query.NodeI // Format is a format string. It will be applied using fmt.Sprintf. If you don't provide a Format string, standard // string conversion operations will be used. Format string // TimeFormat is applied to the data using time.Format. You can have both a Format and TimeFormat, and the Format // will be applied using fmt.Sprintf after the TimeFormat is applied using time.Format. TimeFormat string }
NodeTexter is used by the NodeColumn to get text out of a database column.
type SliceColumn ¶
type SliceColumn struct {
control.ColumnBase
}
SliceColumn is a table that works with data that is in the form of a slice. The data item itself must be convertible into a string, either by normal string conversion semantics, or using the supplied format string.
func NewSliceColumn ¶
func NewSliceColumn(index int) *SliceColumn
NewSliceColumn creates a new column that treats the supplied row data as a slice. It will use the given numeric index to get the data. It will then attempt to convert the data into a string, or you can explicitly tell it how to do this by calling SetFormat. If the data is a Date, Time or DateTime type, you MUST call SetTimeFormat to describe how to format the date or time.
func (*SliceColumn) Init ¶
func (c *SliceColumn) Init(index int)
func (*SliceColumn) SetFormat ¶
func (c *SliceColumn) SetFormat(format string) *SliceColumn
SetFormat sets an optional format string for the column, which will be passed to fmt.Sprintf to format the data.
func (*SliceColumn) SetTimeFormat ¶
func (c *SliceColumn) SetTimeFormat(format string) *SliceColumn
SetTimeFormat sets the format for Date, Time or DateTime type data. The format will be passed to time.Format to produce the text to print for the column.
type SliceTexter ¶
type SliceTexter struct { // Index is the index into the data that corresponds to this table Index int // Format is a format string. It will be applied using fmt.Sprintf. If you don't provide a Format string, standard // string conversion operations will be used. Format string // TimeFormat is applied to the data using time.Format. You can have both a Format and TimeFormat, and the Format // will be applied using fmt.Sprintf after the TimeFormat is applied using time.Format. TimeFormat string }
SliceTexter is the default CellTexter for tables. It lets you get items out of slices.