View Source RecordList.Pagination (record_list v0.1.3)
A module that builds a RecordList.Pagination.t() struct with information about the paging of the records.
Link to this section Summary
Types
The total number of records returned by the query - typically from doing a count prior to paging.
The current page.
The number of records per page.
A struct to capture paging information for use with, for example, paging controls.
Functions
Calculates the tota; number of pages.
Builds a %RecordList.Pagination{} struct from the current_page, per_page and count arguments.
Calculates the offset.
Adds the records_from value. 0 if count is nil, or 0. 1 if the previous_page is nil and otherwise 1 + offset.
Adds the next page unless current page is the last page.
Adds the previous page unless current page is the first page.
Adds the records_to value. 0 if count is nil, or 0. count if count < per_page. records_count if is_nil(next_page). Otherwise current_page * per_page.
The per_page and current_page values can potentially be passed in as strings, e.g. "20" or "2". We ensure that the values are converted to integers in order to do the required calculations.
Link to this section Types
@type count() :: integer()
The total number of records returned by the query - typically from doing a count prior to paging.
The current page.
The number of records per page.
@type t() :: %RecordList.Pagination{ current_page: term(), next_page: term(), per_page: term(), previous_page: term(), records_count: term(), records_from: term(), records_offset: term(), records_to: term(), total_pages: term() }
A struct to capture paging information for use with, for example, paging controls.
attributes
Attributes
:per_page- the number of records to return per page.:records_count- The number of records in the query, prior to applying pagination. The result set to be paged through.:records_from- The:idor:indexof the first record in the paged result set.:records_to- The:idor:indexof the last record in the paged result set.:records_offset- The offset from the start of the result set. This is 1 less than:records_from.:total_pages- The number of pages, givenper_pageto get through the total results.:next_page- the next page number.:previous_page- the previous page number.:current_page- the current page number.
Link to this section Functions
Calculates the tota; number of pages.
@spec build(current_page(), per_page(), count()) :: t()
Builds a %RecordList.Pagination{} struct from the current_page, per_page and count arguments.
Calculates the offset.
Adds the records_from value. 0 if count is nil, or 0. 1 if the previous_page is nil and otherwise 1 + offset.
Adds the next page unless current page is the last page.
Adds the previous page unless current page is the first page.
Adds the records_to value. 0 if count is nil, or 0. count if count < per_page. records_count if is_nil(next_page). Otherwise current_page * per_page.
The per_page and current_page values can potentially be passed in as strings, e.g. "20" or "2". We ensure that the values are converted to integers in order to do the required calculations.