You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

64 lines
1.6 KiB

  1. Paginater [![Build Status](https://drone.io/github.com/Unknwon/paginater/status.png)](https://drone.io/github.com/Unknwon/paginater/latest) [![](http://gocover.io/_badge/github.com/Unknwon/paginater)](http://gocover.io/github.com/Unknwon/paginater)
  2. =========
  3. Package paginater is a helper module for custom pagination calculation.
  4. ## Installation
  5. go get github.com/Unknwon/paginater
  6. ## Getting Started
  7. The following code shows an example of how to use paginater:
  8. ```go
  9. package main
  10. import "github.com/Unknwon/paginater"
  11. func main() {
  12. // Arguments:
  13. // - Total number of rows
  14. // - Number of rows in one page
  15. // - Current page number
  16. // - Number of page links
  17. p := paginater.New(45, 10, 3, 3)
  18. // Then use p as a template object named "Page" in "demo.html"
  19. // ...
  20. }
  21. ```
  22. `demo.html`
  23. ```html
  24. {{if not .Page.IsFirst}}[First](1){{end}}
  25. {{if .Page.HasPrevious}}[Previous]({{.Page.Previous}}){{end}}
  26. {{range .Page.Pages}}
  27. {{if eq .Num -1}}
  28. ...
  29. {{else}}
  30. {{.Num}}{{if .IsCurrent}}(current){{end}}
  31. {{end}}
  32. {{end}}
  33. {{if .Page.HasNext}}[Next]({{.Page.Next}}){{end}}
  34. {{if not .Page.IsLast}}[Last]({{.Page.TotalPages}}){{end}}
  35. ```
  36. Possible output:
  37. ```
  38. [First](1) [Previous](2) ... 2 3(current) 4 ... [Next](4) [Last](5)
  39. ```
  40. As you may guess, if the `Page` value is `-1`, you should print `...` in the HTML as common practice.
  41. ## Getting Help
  42. - [API Documentation](https://gowalker.org/github.com/Unknwon/paginater)
  43. - [File An Issue](https://github.com/Unknwon/paginater/issues/new)
  44. ## License
  45. This project is under Apache v2 License. See the [LICENSE](LICENSE) file for the full license text.