paginate

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Feb 18, 2018 License: MIT Imports: 0 Imported by: 3

README

paginate

Build Status Coverage Status Go Report Card GoDoc

Pagination Logic for your template

Example

{{define "pagination"}}
<div>
    <a href="?page=1">First</a>
    <a href="?page={{.Prev}}">Prev</a>
    {{range .Pages 2 2}}
        {{if eq . 0}}
            <a class="disabled">...</a>
        {{else if eq $.Page .}}
            <a class="active">{{.}}</a>
        {{else}}
            <a href="?page={{.}}">{{.}}</a>
        {{end}}
    {{end}}
    <a href="?page={{.Next}}">Next</a>
    <a href="?page={{.MaxPage}}">Last</a>
</div>
{{end}}

Example

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Paginate

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

Paginate type

func FromLimitOffset

func FromLimitOffset(limit, offset, count int64) Paginate

FromLimitOffset creates new paginate from limit, offset and count

func New

func New(page, perPage, items int64) Paginate

New creates paginate from page, per page, and items

func (Paginate) CanNext

func (p Paginate) CanNext() bool

CanNext returns is current page can go next

func (Paginate) CanPrev

func (p Paginate) CanPrev() bool

CanPrev returns is current page can go prev

func (Paginate) Count

func (p Paginate) Count() int64

Count is the alias for Items

func (Paginate) Items

func (p Paginate) Items() int64

Items returns items

func (Paginate) Limit

func (p Paginate) Limit() int64

Limit returns per page

func (Paginate) LimitOffset

func (p Paginate) LimitOffset() (limit, offset int64)

LimitOffset returns limit and offet

func (Paginate) MaxPage

func (p Paginate) MaxPage() int64

MaxPage returns max page

func (Paginate) Next

func (p Paginate) Next() int64

Next returns next page

func (Paginate) Offset

func (p Paginate) Offset() int64

Offset returns offset for current page

func (Paginate) Page

func (p Paginate) Page() int64

Page returns page

func (Paginate) Pages

func (p Paginate) Pages(around, edge int64) []int64

Pages returns page numbers for paginate

around is the number of page around the current page ex. if current page is 10 and around is 3 the result is 0 7 8 9 10 11 12 13 0

edge is the number of page at the edge ex. if current page is 10, max page is 20 and edge is 2 the result is 1 2 0 10 0 19 20

then if current page is 10, max page is 20, around is 3, and edge is 2 the result is 1 2 0 7 8 9 10 11 12 13 0 19 20

func (Paginate) PerPage

func (p Paginate) PerPage() int64

PerPage returns per page

func (Paginate) Prev

func (p Paginate) Prev() int64

Prev returns prev page

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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