column

package
v0.31.10 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 12, 2024 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AllClickAction = iota + 1000
)

Variables

This section is empty.

Functions

func ButtonColumnClick

func ButtonColumnClick() *event.Event

ButtonColumnClick returns an event that detects a click on the icon in the column. The EventValue will be the row value clicked on. If you need to also know the column clicked on, you can set the EventValue on the associated action to:

javascript.JsCode(`g$(event.goradd.match).columnId()`)

and then get the value from the EventValue.

func GetNode

func GetNode(c *AliasColumn) query.NodeI

func MakeNodeSlice

func MakeNodeSlice(columns []table.ColumnI) []query.NodeI

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 {
	table.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) CellData

func (c *AliasColumn) CellData(ctx context.Context, row int, col int, data interface{}) interface{}

CellData is called by the framework to get the data to display in a cell.

func (*AliasColumn) Deserialize

func (c *AliasColumn) Deserialize(dec page.Decoder)

func (*AliasColumn) Init

func (c *AliasColumn) Init(alias string)

func (*AliasColumn) Serialize

func (c *AliasColumn) Serialize(e page.Encoder)

type AliasColumnCreator

type AliasColumnCreator struct {
	// ID will assign the given id to the column. If you do not specify it, an id will be given it by the framework.
	ID string
	// Alias is the name of the alias to use when getting data out of the provided database row
	Alias string
	// Title is the static title string to use in the header row
	Title string
	// Sortable makes the column display sort arrows in the header
	// Deprecated: Use SortDirection instead
	Sortable bool
	// SortDirection sets the initial sorting direction of the column, and will make the column sortable
	// By default, the column is not sortable.
	SortDirection table.SortDirection
	// IsHtml indicates that the texter is producing HTML rather than text that should be escaped.
	table.ColumnOptions
}

AliasColumnCreator creates a column that displays the content of a database alias. Each row must be an AliasGetter, which by default all the output from database queries provide that.

func (AliasColumnCreator) Create

func (c AliasColumnCreator) Create(ctx context.Context, parent table.TableI) table.ColumnI

type AliasGetter

type AliasGetter interface {
	GetAlias(key string) query.AliasValue
}

type ButtonColumn

type ButtonColumn struct {
	table.ColumnBase
	// contains filtered or unexported fields
}

ButtonColumn is a column that draws a button that fires the ButtonColumnClick event.

func NewButtonColumn

func NewButtonColumn() *ButtonColumn

NewButtonColumn creates a new button column.

func (*ButtonColumn) ButtonAttributes

func (c *ButtonColumn) ButtonAttributes() html5tag.Attributes

ButtonAttributes returns the attributes of the button. You can directly manipulate those.

func (*ButtonColumn) CellData

func (c *ButtonColumn) CellData(ctx context.Context, row int, col int, data interface{}) interface{}

func (*ButtonColumn) Deserialize

func (c *ButtonColumn) Deserialize(dec page.Decoder)

func (*ButtonColumn) Init

func (c *ButtonColumn) Init(self table.ColumnI)

func (*ButtonColumn) Serialize

func (c *ButtonColumn) Serialize(e page.Encoder)

func (*ButtonColumn) SetButtonHtml

func (c *ButtonColumn) SetButtonHtml(h string)

SetButtonHtml sets the html to use inside the button. By default a pencil is drawn. Use `<i class="fas fa-edit" aria-hidden="true"></i>` for a font awesome edit icon

type ButtonColumnCreator

type ButtonColumnCreator struct {
	// ID will assign the given id to the column. If you do not specify it, an id will be given it by the framework.
	ID string
	// Title is the static title string to use in the header row
	Title string
	// ButtonHtml specifies the html to put inside the button
	ButtonHtml string
	// ButtonAttributes lets you set the button attributes how you want.
	ButtonAttributes html5tag.Attributes
	table.ColumnOptions
}

ButtonColumnCreator creates a column that displays a clickable icon.

func (ButtonColumnCreator) Create

type CellTexter

type CellTexter interface {
	table.CellTexter
}

func GetCellTexter

func GetCellTexter(ctrl page.ControlI, id string) CellTexter

type CheckboxColumn

type CheckboxColumn struct {
	table.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

NewCheckboxColumn 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 (c *CheckboxColumn) Action(_ context.Context, params action.Params)

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 (c *CheckboxColumn) AddActions(t page.ControlI)

AddActions adds actions to the table that the column can respond to.

func (*CheckboxColumn) CellText

func (c *CheckboxColumn) CellText(_ context.Context, _ int, _ 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 (c *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 (c *CheckboxColumn) CheckboxAttributes(data interface{}) html5tag.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) Deserialize

func (c *CheckboxColumn) Deserialize(dec page.Decoder)

func (*CheckboxColumn) HeaderCellHtml

func (c *CheckboxColumn) HeaderCellHtml(_ context.Context, _ int, _ int) (h string)

HeaderCellHtml is called by the Table drawing system to draw the HeaderCellHtml.

func (*CheckboxColumn) Init

func (c *CheckboxColumn) Init()

func (*CheckboxColumn) MarshalState

func (c *CheckboxColumn) MarshalState(m page.SavedState)

MarshalState is an internal function to save the state of the control

func (*CheckboxColumn) PreRender

func (c *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

func (c *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) Serialize

func (c *CheckboxColumn) Serialize(e page.Encoder)

func (*CheckboxColumn) SetShowCheckAll

func (c *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

func (c *CheckboxColumn) UnmarshalState(m page.SavedState)

UnmarshalState is an internal function to restore the state of the control

func (*CheckboxColumn) UpdateFormValues

func (c *CheckboxColumn) UpdateFormValues(ctx context.Context)

UpdateFormValues is used by the framework to cause the control to retrieve its values from the form

type CheckboxColumnCreator

type CheckboxColumnCreator struct {
	// ID will assign the given id to the column. If you do not specify it, an id will be given it by the framework.
	ID string
	// ShowCheckAll will show a checkbox in the header that the user can use to check all the boxes in the column.
	ShowCheckAll bool
	// CheckboxProvider tells us which checkboxes are on or off, and how the checkboxes are styled.
	CheckboxProvider CheckboxProvider
	// Title is the title of the column that appears in the header
	Title string
	// Sortable makes the column display sort arrows in the header
	// Deprecated: Use SortDirection instead
	Sortable bool
	// SortDirection sets the initial sorting direction of the column, and will make the column sortable
	// By default, the column is not sortable.
	SortDirection table.SortDirection
	// IsHtml indicates that the texter is producing HTML rather than text that should be escaped.
	table.ColumnOptions
}

CheckboxColumnCreator creates a column of checkboxes.

func (CheckboxColumnCreator) Create

type CheckboxColumnI

type CheckboxColumnI interface {
	table.ColumnI
	CheckboxAttributes(data interface{}) html5tag.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{}) html5tag.Attributes
	// All lets you return a map of all the ids and their initial values if you enable the checkAll box. 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 implement. Be sure to register your custom provider with gob.

type DefaultCheckboxProvider

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

func (c DefaultCheckboxProvider) All() map[string]bool

func (DefaultCheckboxProvider) Attributes

func (c DefaultCheckboxProvider) Attributes(_ interface{}) html5tag.Attributes

func (DefaultCheckboxProvider) DataID

func (c DefaultCheckboxProvider) DataID() string

func (DefaultCheckboxProvider) IsChecked

func (c DefaultCheckboxProvider) IsChecked(_ interface{}) bool

func (DefaultCheckboxProvider) RowID

func (c DefaultCheckboxProvider) RowID(_ interface{}) string

type Getter

type Getter interface {
	Get(string) interface{}
}

type GetterColumn

type GetterColumn struct {
	table.ColumnBase
	// contains filtered or unexported fields
}

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) CellData

func (c *GetterColumn) CellData(_ context.Context, rowNum int, colNum int, data interface{}) interface{}

func (*GetterColumn) Deserialize

func (c *GetterColumn) Deserialize(dec page.Decoder)

func (*GetterColumn) Init

func (c *GetterColumn) Init(index string)

func (*GetterColumn) Serialize

func (c *GetterColumn) Serialize(e page.Encoder)

type GetterColumnCreator

type GetterColumnCreator struct {
	// ID will assign the given id to the column. If you do not specify it, an id will be given it by the framework.
	ID string
	// Index is the value passed to the Get function of each row of the data to get the data for the cell.
	Index string
	// Title is the title that appears in the header of the column
	Title string
	// Format is a format string applied to the data using fmt.Sprintf
	Format string
	// TimeFormat is a format string applied specifically to time data using time.Format
	TimeFormat string
	// Sortable makes the column display sort arrows in the header
	// Deprecated: Use SortDirection instead
	Sortable bool
	// SortDirection sets the initial sorting direction of the column, and will make the column sortable
	// By default, the column is not sortable.
	SortDirection table.SortDirection
	// IsHtml indicates that the texter is producing HTML rather than text that should be escaped.
	table.ColumnOptions
}

GetterColumnCreator creates a column that uses a Getter to get the text of each cell.

func (GetterColumnCreator) Create

type MapColumn

type MapColumn struct {
	table.ColumnBase
	// contains filtered or unexported fields
}

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) CellData

func (c *MapColumn) CellData(_ context.Context, rowNum int, colNum int, data interface{}) interface{}

func (*MapColumn) Deserialize

func (c *MapColumn) Deserialize(dec page.Decoder)

func (*MapColumn) Init

func (c *MapColumn) Init(index interface{})

func (*MapColumn) Serialize

func (c *MapColumn) Serialize(e page.Encoder)

type MapColumnCreator

type MapColumnCreator struct {
	// ID will assign the given id to the column. If you do not specify it, an id will be given it by the framework.
	ID string
	// Index is the key to use to get to the map data
	Index interface{}
	// Title is the title of the column that appears in the header
	Title string
	// Sortable makes the column display sort arrows in the header
	// Deprecated: Use SortDirection instead
	Sortable bool
	// SortDirection sets the initial sorting direction of the column, and will make the column sortable
	// By default, the column is not sortable.
	SortDirection table.SortDirection
	// IsHtml indicates that the texter is producing HTML rather than text that should be escaped.
	table.ColumnOptions
}

MapColumnCreator creates a column that treats each row of data as a map of data. The index can be any valid map index, and the value must be a standard kind of value that can be converted to a string.

func (MapColumnCreator) Create

func (c MapColumnCreator) Create(ctx context.Context, parent table.TableI) table.ColumnI

type NodeColumn

type NodeColumn struct {
	table.ColumnBase
	// contains filtered or unexported fields
}

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) CellData

func (c *NodeColumn) CellData(_ context.Context, _ int, _ int, data interface{}) interface{}

func (*NodeColumn) Deserialize

func (c *NodeColumn) Deserialize(dec page.Decoder)

func (*NodeColumn) GetNode

func (c *NodeColumn) GetNode() query.NodeI

func (*NodeColumn) Init

func (c *NodeColumn) Init(node query.NodeI)

func (*NodeColumn) Serialize

func (c *NodeColumn) Serialize(e page.Encoder)

type NodeColumnCreator

type NodeColumnCreator struct {
	// ID will assign the given id to the column. If you do not specify it, an id will be given it by the framework.
	ID string
	// Node is a database node generated by the code generator
	Node query.NodeI
	// Title is the title of the column that will appear in the header
	Title string
	// Sortable makes the column display sort arrows in the header
	// Deprecated: Use SortDirection instead
	Sortable bool
	// SortDirection sets the initial sorting direction of the column, and will make the column sortable
	// By default, the column is not sortable.
	SortDirection table.SortDirection
	// IsHtml indicates that the texter is producing HTML rather than text that should be escaped.
	table.ColumnOptions
}

NodeColumnCreator creates a column that treats each row as data from the ORM, and gets to that data using a database Node.

func (NodeColumnCreator) Create

func (c NodeColumnCreator) Create(ctx context.Context, parent table.TableI) table.ColumnI

type NodeGetter

type NodeGetter interface {
	GetNode() query.NodeI
}

type SliceColumn

type SliceColumn struct {
	table.ColumnBase
	// contains filtered or unexported fields
}

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) CellData

func (c *SliceColumn) CellData(_ context.Context, _ int, _ int, data interface{}) interface{}

func (*SliceColumn) Deserialize

func (c *SliceColumn) Deserialize(dec page.Decoder)

func (*SliceColumn) Init

func (c *SliceColumn) Init(index int)

func (*SliceColumn) Serialize

func (c *SliceColumn) Serialize(e page.Encoder)

type SliceColumnCreator

type SliceColumnCreator struct {
	// ID will assign the given id to the column. If you do not specify it, an id will be given it by the framework.
	ID string
	// Index is the slice index that will be used to get to the data in the column
	Index int
	// Title is the title of the column and will appear in the header
	Title string
	// Sortable makes the column display sort arrows in the header
	// Deprecated: Use SortDirection instead
	Sortable bool
	// SortDirection sets the initial sorting direction of the column, and will make the column sortable
	// By default, the column is not sortable.
	SortDirection table.SortDirection
	// IsHtml indicates that the texter is producing HTML rather than text that should be escaped.
	table.ColumnOptions
}

SliceColumnCreator creates a column that treats each row as a slice of data.

func (SliceColumnCreator) Create

func (c SliceColumnCreator) Create(ctx context.Context, parent table.TableI) table.ColumnI

type StringGetter

type StringGetter interface {
	Get(string) string
}

type TexterColumn

type TexterColumn struct {
	table.ColumnBase
}

TexterColumn is a table column that lets you use a CellTexter to specify the content of the cells in the column. 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 NewTexterColumn

func NewTexterColumn(texter CellTexter) *TexterColumn

NewTexterColumn creates a new column with a custom cell texter.

func (*TexterColumn) Init

func (c *TexterColumn) Init(texter CellTexter)

type TexterColumnCreator

type TexterColumnCreator struct {
	// ID will assign the given id to the column. If you do not specify it, an id will be given it by the framework.
	ID string
	// Texter is a CellTexter that returns the text that should go in each cell.
	Texter CellTexter
	// TexterID is the control id of a CellTexter.
	TexterID string
	// Title is the title at the top of the column
	Title string
	// Sortable makes the column display sort arrows in the header
	// Deprecated: Use SortDirection instead
	Sortable bool
	// SortDirection sets the initial sorting direction of the column, and will make the column sortable
	// By default, the column is not sortable.
	SortDirection table.SortDirection
	// IsHtml indicates that the texter is producing HTML rather than text that should be escaped.
	IsHtml bool
	table.ColumnOptions
}

TexterColumnCreator creates a column that uses a CellTexter to get the content of each cell.

func (TexterColumnCreator) Create

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL