pagination

package
v1.7.0 Latest Latest
Warning

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

Go to latest
Published: May 12, 2025 License: GPL-2.0 Imports: 11 Imported by: 0

Documentation

Overview

templ: version: v0.3.833

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNoResults = errors.New("no results found")
)

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[T]
	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]
}

type Pagination

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

type Paginator

type Paginator[T any] struct {
	GetObject  func(T) T
	GetObjects func(amount int, offset int) ([]T, error)
	GetCount   func() (int, error)
	Amount     int
	// contains filtered or unexported fields
}

Paginator holds pagination logic

func (*Paginator[T]) Count

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

func (*Paginator[T]) NumPages

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

func (*Paginator[T]) Page

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

func (*Paginator[T]) PerPage

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

Jump to

Keyboard shortcuts

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