pages

package module
v0.0.0-...-ec63c63 Latest Latest
Warning

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

Go to latest
Published: Nov 30, 2025 License: MIT Imports: 1 Imported by: 1 module, 1 package

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Option

type Option func(*Paginator)

Option is used to set options in New.

func WithLooping

func WithLooping(loop bool) Option

WithLooping sets pagination to loop.

func WithPerPage

func WithPerPage(perPage int) Option

WithPerPage sets the total pages.

type Pages

type Pages[P any] struct {
	*Paginator
	// contains filtered or unexported fields
}

func New

func New[T any](stuff []T, opts ...Option) *Pages[T]

func (Pages[T]) AllPages

func (p Pages[T]) AllPages() [][]T

AllPages returns all pages as a slice of slices.

func (Pages[T]) Current

func (p Pages[T]) Current() []T

Current returns the current page slice.

func (Pages[T]) Next

func (p Pages[T]) Next() []T

Next returns the next page, without changing the current page number. Use is for pre-rendering the next page.

func (Pages[T]) Prev

func (p Pages[T]) Prev() []T

Prev returns the prev page, without changing the current page number. Use is for pre-rendering the prev page.

type Paginator

type Paginator struct {
	// Page is the current page number.
	Page int
	// PerPage is the number of items per page.
	PerPage int
	// TotalPages is the total number of pages.
	TotalPages int
	// Loop determines whether or not to go to the first page, after the last
	Loop bool
}

func NewPaginator

func NewPaginator(opts ...Option) Paginator

NewPaginator creates a new model with defaults.

func (*Paginator) GetSliceBounds

func (m *Paginator) GetSliceBounds(length int) (start int, end int)

GetSliceBounds is a helper function for paginating slices. Pass the length of the slice you're rendering and you'll receive the start and end bounds corresponding to the pagination. For example:

bunchOfStuff := []stuff{...}
start, end := model.GetSliceBounds(len(bunchOfStuff))
sliceToRender := bunchOfStuff[start:end]

func (Paginator) ItemsOnPage

func (m Paginator) ItemsOnPage(totalItems int) int

ItemsOnPage is a helper function for returning the number of items on the current page given the total number of items passed as an argument.

func (*Paginator) NextPage

func (m *Paginator) NextPage()

NextPage is a helper function for navigating one page forward. It will not page beyond the last page (i.e. totalPages - 1).

func (*Paginator) NextPageNum

func (m *Paginator) NextPageNum() int

func (Paginator) OnFirstPage

func (m Paginator) OnFirstPage() bool

OnFirstPage returns whether or not we're on the first page.

func (Paginator) OnLastPage

func (m Paginator) OnLastPage() bool

OnLastPage returns whether or not we're on the last page.

func (*Paginator) PrevPage

func (m *Paginator) PrevPage()

PrevPage is a helper function for navigating one page backward. It will not page beyond the first page (i.e. page 0).

func (*Paginator) PrevPageNum

func (m *Paginator) PrevPageNum() int

func (*Paginator) SetTotalPages

func (m *Paginator) SetTotalPages(items int) int

SetTotalPages is a helper function for calculating the total number of pages from a given number of items. Its use is optional since this pager can be used for other things beyond navigating sets. Note that it both returns the number of total pages and alters the model.

Jump to

Keyboard shortcuts

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