Documentation
¶
Overview ¶
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Index ¶
- type Option
- type Pages
- type Paginator
- func (m *Paginator) GetSliceBounds(length int) (start int, end int)
- func (m Paginator) ItemsOnPage(totalItems int) int
- func (m *Paginator) NextPage()
- func (m *Paginator) NextPageNum() int
- func (m Paginator) OnFirstPage() bool
- func (m Paginator) OnLastPage() bool
- func (m *Paginator) PrevPage()
- func (m *Paginator) PrevPageNum() int
- func (m *Paginator) SetTotalPages(items int) int
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Pages ¶
func (Pages[T]) AllPages ¶
func (p Pages[T]) AllPages() [][]T
AllPages returns all pages as a slice of slices.
type Paginator ¶
type Paginator struct {
// Page is the current page number.
Page int
// PerPage is the number of items per page.
PerPage int
// TotalPages is the total number of pages.
TotalPages int
// Loop determines whether or not to go to the first page, after the last
Loop bool
}
func NewPaginator ¶
NewPaginator creates a new model with defaults.
func (*Paginator) GetSliceBounds ¶
GetSliceBounds is a helper function for paginating slices. Pass the length of the slice you're rendering and you'll receive the start and end bounds corresponding to the pagination. For example:
bunchOfStuff := []stuff{...}
start, end := model.GetSliceBounds(len(bunchOfStuff))
sliceToRender := bunchOfStuff[start:end]
func (Paginator) ItemsOnPage ¶
ItemsOnPage is a helper function for returning the number of items on the current page given the total number of items passed as an argument.
func (*Paginator) NextPage ¶
func (m *Paginator) NextPage()
NextPage is a helper function for navigating one page forward. It will not page beyond the last page (i.e. totalPages - 1).
func (*Paginator) NextPageNum ¶
func (Paginator) OnFirstPage ¶
OnFirstPage returns whether or not we're on the first page.
func (Paginator) OnLastPage ¶
OnLastPage returns whether or not we're on the last page.
func (*Paginator) PrevPage ¶
func (m *Paginator) PrevPage()
PrevPage is a helper function for navigating one page backward. It will not page beyond the first page (i.e. page 0).
func (*Paginator) PrevPageNum ¶
func (*Paginator) SetTotalPages ¶
SetTotalPages is a helper function for calculating the total number of pages from a given number of items. Its use is optional since this pager can be used for other things beyond navigating sets. Note that it both returns the number of total pages and alters the model.