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:
- (recommended) to make a regular match replace the output content to implement the customization;
- Self-organizing pagination content implementation according to the methods exposed by the paging object;
- 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: