pagination

package module
v0.0.0-...-2470f1b Latest Latest
Warning

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

Go to latest
Published: Aug 22, 2017 License: MIT Imports: 6 Imported by: 0

README

Paginator

It's can generate any href you want, and it depends on beego/orm

Install

go get github.com/doorOfChoice/pagination

Use

    //o: need a query seter, such as o.QueryTable("user")
    //tp: the interface to get datas
    //params[0], count of show href link in paginatior DEFAULT:5
    //params[1], count of show data in per page DEFAULT 15
    func NewPaginator(r *http.Request, o orm.QuerySeter, tp interface{}, params ...int64) *Paginator 

userController.go

    // If I has a model is User
    type User struct{
        Id int `orm:"auto;pk"`
        Name string 
    }

    func (c *UserController) GetAllUsers() {
        var users []*User

        o := orm.NewOrm()
        //generate a paginator
        paginator := pagination.NewPaginator(
            c.Ctx.Request,
            o.Query("user").Filter("id" > 5),
            &users,
            15,
            15,
        )

        c.Data["P"] = paginator
        c.Data["Users"] = users
        c.TplName = "user.tpl"
    }

Param

There are some params, you can use it in template

   type Paginator struct {

	PageLinkPrev  string 
	PageLinkNext  string
	PageLinkLast  string
	PageLinkFirst string

	PerValue     int64
	MaxValue     int64  //sum of data in the table
	CurrentValue int64  //how many data in current page

	CurrentPage int64
	MaxPage     int64

	BasePath  string
	Links     []Link    //generated links
}

type Link struct {
	Id        int64 //which page
	IsCurrent bool  //is current page
	Href      string//the href
}

License

MIT

Documentation

Index

Constants

View Source
const (
	DEFAULT_PERPAGE   = 15
	DEFAULT_LINKCOUNT = 5
)

Variables

This section is empty.

Functions

func LoadLink(path, key string, value interface{}) string

generate url include query string

Types

type Link struct {
	Id        int64
	IsCurrent bool
	Href      string
}

type Paginator

type Paginator struct {
	Request *http.Request

	PageLinkPrev  string
	PageLinkNext  string
	PageLinkLast  string
	PageLinkFirst string

	PerValue     int64
	MaxValue     int64
	CurrentValue int64

	CurrentPage int64
	MaxPage     int64

	OffsetFrom int64 //开始下标,用于区域分页
	OffsetTo   int64 //结束下标,用于区域分页

	BasePath  string
	Data      interface{}
	Links     []Link
	LinkCount int64
	// contains filtered or unexported fields
}

func NewPaginator

func NewPaginator(r *http.Request, o orm.QuerySeter, tp interface{}, params ...int64) *Paginator

o: need a query seter, such as o.QueryTable("user") tp: the interface to get datas params[0], count of show href link in paginatior DEFAULT:5 params[1], count of show data in per page DEFAULT 15

func NewPaginatorByFiled

func NewPaginatorByFiled(r *http.Request, tp interface{}, field string, params ...int64) *Paginator

o: need a query seter, such as o.QueryTable("user") tp: the interface to get datas params[0], count of show href link in paginatior DEFAULT:5 params[1], count of show data in per page DEFAULT 15

Jump to

Keyboard shortcuts

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