README
¶
Paginater
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 ¶
- type Page
- type Paginater
- func (p *Paginater) Current() int
- func (p *Paginater) HasNext() bool
- func (p *Paginater) HasPrevious() bool
- func (p *Paginater) IsFirst() bool
- func (p *Paginater) IsLast() bool
- func (p *Paginater) Next() int
- func (p *Paginater) Pages() []*Page
- func (p *Paginater) PagingNum() int
- func (p *Paginater) Previous() int
- func (p *Paginater) Total() int
- func (p *Paginater) TotalPages() int
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.
type Paginater ¶
type Paginater struct {
// contains filtered or unexported fields
}
Paginater represents a set of results of pagination calculations.
func (*Paginater) HasPrevious ¶
HasPrevious returns true if there is a previous page relative to current page.
func (*Paginater) Pages ¶
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) TotalPages ¶
TotalPage returns number of total pages.