GF Frame Paging Module (v)-Custom paging

Source: Internet
Author: User
This is a creation in Article, where the information may have evolved or changed.

Article Source: http://gf.johng.cn/597435

Because of the limited number of predefined styles for paging objects, sometimes we want to customize the style of pagination (label output), which gives developers a very high degree of flexibility in customizing page styles because all methods of paging objects are public. Developers can implement custom paging content in the following ways:

    1. (recommended) to make a regular match replace the output content to implement the customization;
    2. Self-organizing pagination content implementation according to the methods exposed by the paging object;
    3. You can also customize a paging object (inherited from the original paging object) and use the method overload to implement the customization;

Example 1, use the first way to implement paging customization:

Package Mainimport ("gitee.com/johng/gf/g" "Gitee.com/johng/gf/g/os/gview" "Gitee.com/johng/gf/g/util/gstr" " Gitee.com/johng/gf/g/net/ghttp "" gitee.com/johng/gf/g/util/gpage ")//Paging tab uses the LI tag to wrap the Func wrapcontent (page *gpage. Page) string {content: = page. GetContent (4) content = Gstr. Replacebymap (content, map[string]string {"<span": "<li><span", "/span>": "/span></l I> "," <a ":" <li><a ","/a> ":"/a></li> ",}) return" <ul> "+ C Ontent + "</ul>"}func main () {s: = Ghttp. Getserver () S.bindhandler ("/page/custom2/*page", func (R *ghttp). Request) {page: = Gpage. New (+, R.get ("page"), R.url. String (), R.router.uri) Content: = wrapcontent (page) buffer, _: = Gview. Parsecontent (' 

After execution, the page output is:

Example 2, use the second way to implement paging customization:

Package Mainimport ("Gitee.com/johng/gf/g/os/gview" "Gitee.com/johng/gf/g/net/ghttp" "gitee.com/johng/gf/g/util/ Gpage ")//Custom Paging name Func pagecontent (page *gpage. Page) string {page. Nextpagetag = "NextPage" page. Prevpagetag = "PrevPage" page. Firstpagetag = "Homepage" page. Lastpagetag = "LastPage" pagestr: = page. FirstPage () Pagestr + = page. PrevPage () Pagestr + = page. Pagebar ("Current-page") pagestr + = page. NextPage () Pagestr + = page. LastPage () return Pagestr}func main () {s: = Ghttp. Getserver () S.bindhandler ("/page/custom/*page", func (R *ghttp). Request) {page: = Gpage. New (+, R.get ("page"), R.url. String (), R.router.uri) buffer, _: = Gview. Parsecontent (' 

After the

Executes, the page output is:

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.