paginater

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

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

Go to latest
Published: Mar 8, 2020 License: Apache-2.0 Imports: 0 Imported by: 0

README

Paginater Build Status

Package paginater is a helper module for custom pagination calculation.

Installation

go get github.com/Unknwon/paginater

Getting Started

The following code shows an example of how to use paginater:

package main

import "github.com/Unknwon/paginater"

func main() {
	// Arguments:
	// - Total number of rows
	// - Number of rows in one page
	// - Current page number 
	// - Number of page links to be displayed
	p := paginater.New(45, 10, 3, 3)
	
	// Then use p as a template object named "Page" in "demo.html"
	// ...
}

demo.html

{{if not .Page.IsFirst}}[First](1){{end}}
{{if .Page.HasPrevious}}[Previous]({{.Page.Previous}}){{end}}

{{range .Page.Pages}}
	{{if eq .Num -1}}
	...
	{{else}}
	{{.Num}}{{if .IsCurrent}}(current){{end}}
	{{end}}
{{end}}

{{if .Page.HasNext}}[Next]({{.Page.Next}}){{end}}
{{if not .Page.IsLast}}[Last]({{.Page.TotalPages}}){{end}}

Possible output:

[First](1) [Previous](2) ... 2 3(current) 4 ... [Next](4) [Last](5)

As you may guess, if the Page value is -1, you should print ... in the HTML as common practice.

Getting Help

License

This project is under Apache v2 License. See the LICENSE file for the full license text.

Documentation

Overview

Package paginater is a helper module for custom pagination calculation.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Page

type Page struct {
	// contains filtered or unexported fields
}

Page presents a page in the paginater.

func (*Page) IsCurrent

func (p *Page) IsCurrent() bool

func (*Page) Num

func (p *Page) Num() int

type Paginater

type Paginater struct {
	// contains filtered or unexported fields
}

Paginater represents a set of results of pagination calculations.

func New

func New(total, pagingNum, current, numPages int) *Paginater

New initialize a new pagination calculation and returns a Paginater as result.

func (*Paginater) Current

func (p *Paginater) Current() int

Current returns current page number.

func (*Paginater) HasNext

func (p *Paginater) HasNext() bool

HasNext returns true if there is a next page relative to current page.

func (*Paginater) HasPrevious

func (p *Paginater) HasPrevious() bool

HasPrevious returns true if there is a previous page relative to current page.

func (*Paginater) IsFirst

func (p *Paginater) IsFirst() bool

IsFirst returns true if current page is the first page.

func (*Paginater) IsLast

func (p *Paginater) IsLast() bool

IsLast returns true if current page is the last page.

func (*Paginater) Next

func (p *Paginater) Next() int

func (*Paginater) Pages

func (p *Paginater) Pages() []*Page

Pages returns a list of nearby page numbers relative to current page. If value is -1 means "..." that more pages are not showing.

func (*Paginater) PagingNum

func (p *Paginater) PagingNum() int

PagingNum returns number of page size.

func (*Paginater) Previous

func (p *Paginater) Previous() int

func (*Paginater) Total

func (p *Paginater) Total() int

Total returns number of total rows.

func (*Paginater) TotalPages

func (p *Paginater) TotalPages() int

TotalPage returns number of total pages.

Jump to

Keyboard shortcuts

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