gf: Index | Files

package gpage

import ""

Package gpage provides useful paging functionality for web pages.


Package Files



const (
    PAGE_NAME         = "page"    // PAGE_NAME defines the default page name.
    PAGE_PLACE_HOLDER = "{.page}" // PAGE_PLACE_HOLDER defines the place holder for the url template.

type Page Uses

type Page struct {
    TotalSize      int    // Total size.
    TotalPage      int    // Total page, which is automatically calculated.
    CurrentPage    int    // Current page number >= 1.
    UrlTemplate    string // Custom url template for page url producing.
    LinkStyle      string // CSS style name for HTML link tag <a>.
    SpanStyle      string // CSS style name for HTML span tag <span>, which is used for first, current and last page tag.
    SelectStyle    string // CSS style name for HTML select tag <select>.
    NextPageTag    string // Tag name for next p.
    PrevPageTag    string // Tag name for prev p.
    FirstPageTag   string // Tag name for first p.
    LastPageTag    string // Tag name for last p.
    PrevBarTag     string // Tag string for prev bar.
    NextBarTag     string // Tag string for next bar.
    PageBarNum     int    // Page bar number for displaying.
    AjaxActionName string // Ajax function name. Ajax is enabled if this attribute is not empty.

Page is the pagination implementer. All the attributes are public, you can change them when necessary.

func New Uses

func New(totalSize, pageSize, currentPage int, urlTemplate string) *Page

New creates and returns a pagination manager. Note that the parameter <urlTemplate> specifies the URL producing template, like: /user/list/{.page}, /user/list/{.page}.html, /user/list?page={.page}&type=1, etc. The build-in variable in <urlTemplate> "{.page}" specifies the page number, which will be replaced by certain page number when producing.

func (*Page) FirstPage Uses

func (p *Page) FirstPage() string

FirstPage returns the HTML content for the first page.

func (*Page) GetContent Uses

func (p *Page) GetContent(mode int) string

GetContent returns the page content for predefined mode. These predefined contents are mainly for chinese localization purpose. You can defines your own page function retrieving the page content according to the implementation of this function.

func (p *Page) GetLink(page int, text, title string) string

GetLink returns the HTML link tag <a> content for given page number.

func (*Page) GetUrl Uses

func (p *Page) GetUrl(page int) string

GetUrl parses the UrlTemplate with given page number and returns the URL string. Note that the UrlTemplate attribute can be either an URL or a URI string with "{.page}" place holder specifying the page number position.

func (*Page) LastPage Uses

func (p *Page) LastPage() string

LastPage returns the HTML content for the last page.

func (*Page) NextPage Uses

func (p *Page) NextPage() string

NextPage returns the HTML content for the next page.

func (*Page) PageBar Uses

func (p *Page) PageBar() string

PageBar returns the HTML page bar content with link and span tags.

func (*Page) PrevPage Uses

func (p *Page) PrevPage() string

PrevPage returns the HTML content for the previous page.

func (*Page) SelectBar Uses

func (p *Page) SelectBar() string

SelectBar returns the select HTML content for pagination.

Package gpage imports 4 packages (graph) and is imported by 1 packages. Updated 2020-03-23. Refresh now. Tools for package owners.