paginate

package module
v1.1.2 Latest Latest
Warning

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

Go to latest
Published: Aug 27, 2019 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 MovablePaginate added in v1.1.0

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

MovablePaginate is the paginate for movable list

func NewMovable added in v1.1.0

func NewMovable(page, perPage, pages int64) *MovablePaginate

NewMovable creates new movable paginate

func (*MovablePaginate) CanNext added in v1.1.0

func (p *MovablePaginate) CanNext() bool

CanNext returns is current page can go next

func (*MovablePaginate) CanPrev added in v1.1.0

func (p *MovablePaginate) CanPrev() bool

CanPrev returns is current page can go prev

func (*MovablePaginate) Count added in v1.1.0

func (p *MovablePaginate) Count() int64

Count return count

func (*MovablePaginate) CountLimit added in v1.1.1

func (p *MovablePaginate) CountLimit() int64

CountLimit returns limit for count

func (*MovablePaginate) CountOffset added in v1.1.1

func (p *MovablePaginate) CountOffset() int64

CountOffset returns offset for count

func (*MovablePaginate) Counting added in v1.1.1

func (p *MovablePaginate) Counting(counter func(limit, offset int64) int64)

Counting runs set count from counter function

func (*MovablePaginate) First added in v1.1.0

func (p *MovablePaginate) First() int64

First returns first page in paginate

func (*MovablePaginate) Limit added in v1.1.0

func (p *MovablePaginate) Limit() int64

Limit returns per page

func (*MovablePaginate) LimitOffset added in v1.1.0

func (p *MovablePaginate) LimitOffset() (limit, offset int64)

LimitOffset returns limit and offet

func (*MovablePaginate) MaxPage added in v1.1.0

func (p *MovablePaginate) MaxPage() int64

MaxPage returns max page

func (*MovablePaginate) Next added in v1.1.0

func (p *MovablePaginate) Next() int64

Next returns next page

func (*MovablePaginate) Offset added in v1.1.0

func (p *MovablePaginate) Offset() int64

Offset returns offset for current page

func (*MovablePaginate) Page added in v1.1.0

func (p *MovablePaginate) Page() int64

Page returns page

func (*MovablePaginate) Pages added in v1.1.0

func (p *MovablePaginate) Pages() []int64

Pages returns page number for paginate without last page

func (*MovablePaginate) PerPage added in v1.1.0

func (p *MovablePaginate) PerPage() int64

PerPage returns per page

func (*MovablePaginate) Prev added in v1.1.0

func (p *MovablePaginate) Prev() int64

Prev returns prev page

func (*MovablePaginate) SetCount added in v1.1.0

func (p *MovablePaginate) SetCount(cnt int64) *MovablePaginate

SetCount sets count where cnt is the count of next page to show

`select count(*) from (select * from table offset {CountOffset} limit {CountLimit}) as t;`

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