tables

package
v0.5.3 Latest Latest
Warning

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

Go to latest
Published: Jul 6, 2025 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultLimits = []int{5, 10, 25, 50}

DefaultLimits is a list of default limits.

Functions

func Next

func Next(p PaginationProps) htmx.Node

Next is a component that renders a next button.

func Paginate

func Paginate[T any](_ interface{}, pagination *Paginated[T], _ *gorm.DB) func(db *gorm.DB) *gorm.DB

Paginate returns a function that paginates the results.

func PaginatedResults

func PaginatedResults[T any](value interface{}, pagination *Results[T], db *gorm.DB) func(db *gorm.DB) *gorm.DB

PaginatedResults returns a function that paginates the results.

func Pagination

func Pagination(p PaginationProps, children ...htmx.Node) htmx.Node

Pagination is a component that renders a pagination.

func Prev

func Prev(p PaginationProps) htmx.Node

Prev is a component that renders a previous button.

func RowsPtr

func RowsPtr[T any](rows []T) []*T

RowsPtr is a function that returns the rows as pointers.

func Search(props SearchProps, children ...htmx.Node) htmx.Node

Search is a component that renders a search.

func Select

func Select(p SelectProps, children ...htmx.Node) htmx.Node

Select is a component that renders a select.

func Table

func Table[S ~[]R, R Row](p TableProps, columns Columns[R], s S) htmx.Node

Table is a struct that contains the properties of a table.

func TablePagination

func TablePagination(p TablePaginationProps, children ...htmx.Node) htmx.Node

TablePagination is a component that renders a table pagination.

func TableToolbar

func TableToolbar(p TableToolbarProps, children ...htmx.Node) htmx.Node

TableToolbar is a component that renders a table toolbar.

Types

type ColumnDef

type ColumnDef[R Row] struct {
	// ID is the id of the column.
	ID string
	// AccessorKey is the accessor key of the column.
	AccessorKey string
	// Header is the header of the column.
	Header func(p TableProps) htmx.Node
	// Cell is the cell of the column.
	Cell func(p TableProps, row R) htmx.Node
	// EnableSorting is a flag to enable sorting.
	EnableSorting bool
	// EnableFiltering is a flag to enable filtering.
	EnableFiltering bool
}

ColumnDef returns a new column definition.

type Columns

type Columns[R Row] []ColumnDef[R]

Columns returns a new column definition.

type Paginated

type Paginated[T any] struct {
	// Limit is the number of items to return.
	Limit int `json:"limit" xml:"limit" form:"limit" query:"limit"`
	// Offset is the number of items to skip.
	Offset int `json:"offset" xml:"offset" form:"offset" query:"offset"`
	// Search is the search term to filter the results.
	Search string `json:"search,omitempty" xml:"search" form:"search" query:"search"`
	// Sort is the sorting order.
	Sort string `json:"sort,omitempty" xml:"sort" form:"sort" query:"sort"`
	// Value is the value to paginate.
	Value T `json:"value,omitempty" xml:"value" form:"value" query:"value"`
}

Paginated is a struct that contains the properties of a pagination.

func (*Paginated[T]) GetLimit

func (p *Paginated[T]) GetLimit() int

GetLimit returns the limit.

func (*Paginated[T]) GetOffset

func (p *Paginated[T]) GetOffset() int

GetOffset returns the page.

func (*Paginated[T]) GetSearch

func (p *Paginated[T]) GetSearch() string

GetSearch returns the search.

func (*Paginated[T]) GetSort

func (p *Paginated[T]) GetSort() string

GetSort returns the sort.

type PaginationProps

type PaginationProps struct {
	// ClassNames is a struct that contains the class names of a pagination.
	ClassNames htmx.ClassNames
	// Limit is the number of items to return.
	Limit int
	// Offset is the number of items to skip.
	Offset int
	// Target is the target of the pagination.
	Target string
	// Total is the total number of items.
	Total int
	// URL is the URL of the pagination.
	URL string
}

PaginationProps is a struct that contains the properties of a pagination.

type Results

type Results[T any] struct {
	// Limit is the number of items to return.
	Limit int `json:"limit" xml:"limit" form:"limit" query:"limit"`
	// Offset is the number of items to skip.
	Offset int `json:"offset" xml:"offset" form:"offset" query:"offset"`
	// Search is the search term to filter the results.
	Search string `json:"search,omitempty" xml:"search" form:"search" query:"search"`
	// SearchFields is the search term to filter the results.
	SearchFields []string `json:"-"`
	// Sort is the sorting order.
	Sort string `json:"sort,omitempty" xml:"sort" form:"sort" query:"sort"`
	// TotalRows is the total number of rows.
	TotalRows int `json:"total_rows"`
	// TotalPages is the total number of pages.
	TotalPages int `json:"total_pages"`
	// Rows is the items to return.
	Rows []T `json:"rows" xml:"rows"`
}

Results is a struct that contains the results of a query.

func (*Results[T]) GetLen

func (p *Results[T]) GetLen() int

GetLen returns the length of the rows.

func (*Results[T]) GetLimit

func (p *Results[T]) GetLimit() int

GetLimit returns the limit.

func (*Results[T]) GetOffset

func (p *Results[T]) GetOffset() int

GetOffset returns the page.

func (*Results[T]) GetRows

func (p *Results[T]) GetRows() []*T

GetRows returns the rows as pointers.

func (*Results[T]) GetSearch

func (p *Results[T]) GetSearch() string

GetSearch returns the search.

func (*Results[T]) GetSort

func (p *Results[T]) GetSort() string

GetSort returns the sort.

func (*Results[T]) GetTotalPages

func (p *Results[T]) GetTotalPages() int

GetTotalPages returns the total pages.

func (*Results[T]) GetTotalRows

func (p *Results[T]) GetTotalRows() int

GetTotalRows returns the total rows.

type Row

type Row interface {
	comparable
}

Row is a struct that contains the properties of a row.

type SearchProps

type SearchProps struct {
	// ClassNames is a struct that contains the class names of a search.
	ClassNames htmx.ClassNames
	// Placehholder is the placeholder of the search.
	Placeholder string
	// URL is the URL of the search.
	URL string
	// Name is the name of the search.
	Name string
	// Value is the value of the search.
	Value string
}

SearchProps are the properties of a search.

type SelectProps

type SelectProps struct {
	// ID is the id of the select.
	ID string
	// ClassNames is a struct that contains the class names of a select.
	ClassNames htmx.ClassNames
	// Limit is the number of items to return.
	Limit int
	// Limits is a list of limits.
	Limits []int
	// Offset is the number of items to skip.
	Offset int
	// Target is the target of the select.
	Target string
	// Total is the total number of items.
	Total int
	// URL is the URL of the select.
	URL string
}

SelectProps are the properties of a select.

type TablePaginationProps

type TablePaginationProps struct {
	ClassNames htmx.ClassNames
}

TablePaginationProps is a struct that contains the properties of a table pagination.

type TableProps

type TableProps struct {
	// ClassNames is a struct that contains the class names of a table.
	ClassNames htmx.ClassNames
	// ID is the id of the table.
	ID string
	// Pagination is the pagination of the table.
	Pagination htmx.Node
	// Toolbar is the toolbar of the table.
	Toolbar htmx.Node
}

TableProps is a struct that contains the properties of a table.

type TableToolbarProps

type TableToolbarProps struct {
	ClassNames htmx.ClassNames
}

TableToolbarProps is a struct that contains the properties of a table toolbar.

Jump to

Keyboard shortcuts

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