pagination

package
v1.7.4 Latest Latest
Warning

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

Go to latest
Published: Jul 8, 2026 License: GPL-2.0 Imports: 14 Imported by: 0

Documentation

Overview

templ: version: v0.3.1020

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetPageNum

func GetPageNum(n any) int

Types

type PageObject

type PageObject[T any] interface {
	// The number of objects on this page.
	//
	// This is NOT the total number of objects in the paginator.
	//
	// This might be less than the per page amount
	Count() int

	// A list of results on this page
	// Results() iter.Seq[S, E]
	Results() []T

	// The current page number
	PageNum() int

	// If the page has a next page
	HasNext() bool

	// If the page has a previous page
	HasPrev() bool

	// The next page number
	// This should return -1 if there is no next page
	Next() int

	// The previous page number
	// This should return -1 if there is no previous page
	Prev() int

	// A backreference to the paginator
	Paginator() Pagination[T]
}

func NewPageObject added in v1.7.2

func NewPageObject[T any](ctx context.Context, paginator Pagination[T], num int, results []T) PageObject[T]

type Pagination

type Pagination[T any] interface {
	// The amount of objects total
	// This is used to calculate the number of pages
	BaseURL() string
	Count() (int, error)
	Page(n int) (PageObject[T], error)
	NumPages() (int, error)
	PerPage() int
}

type Paginator

type Paginator[S ~[]E, E any] struct {
	Context    context.Context
	GetObject  func(E) E
	GetObjects func(amount int, offset int) (S, error)
	GetCount   func() (int, error)
	Amount     int
	URL        string
	// contains filtered or unexported fields
}

Paginator holds pagination logic

func (*Paginator[S, E]) BaseURL added in v1.7.2

func (p *Paginator[S, E]) BaseURL() string

func (*Paginator[S, E]) Count

func (p *Paginator[S, E]) Count() (int, error)

func (*Paginator[S, E]) NumPages

func (p *Paginator[S, E]) NumPages() (int, error)

func (*Paginator[S, E]) Page

func (p *Paginator[S, E]) Page(n int) (PageObject[E], error)

func (*Paginator[S, E]) PerPage

func (p *Paginator[S, E]) PerPage() int

type QueryPaginator added in v1.7.2

type QueryPaginator[T attrs.Definer] struct {
	Context      context.Context
	BaseQuerySet func() *queries.QuerySet[T]
	GetObject    func(T) T
	URL          string
	Amount       int
	// contains filtered or unexported fields
}

QueryPaginator holds pagination logic

func (*QueryPaginator[T]) BaseURL added in v1.7.2

func (p *QueryPaginator[T]) BaseURL() string

func (*QueryPaginator[T]) Count added in v1.7.2

func (p *QueryPaginator[T]) Count() (int, error)

func (*QueryPaginator[T]) GetQuerySet added in v1.7.2

func (p *QueryPaginator[T]) GetQuerySet() *queries.QuerySet[T]

func (*QueryPaginator[T]) NumPages added in v1.7.2

func (p *QueryPaginator[T]) NumPages() (int, error)

func (*QueryPaginator[T]) Page added in v1.7.2

func (p *QueryPaginator[T]) Page(n int) (PageObject[T], error)

func (*QueryPaginator[T]) PerPage added in v1.7.2

func (p *QueryPaginator[T]) PerPage() int

Jump to

Keyboard shortcuts

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