When displaying long lists of data it is often preferable to add paging to the list. By using paging, data is loaded in small blocks improving load times and reducing the workload on the server providing the data.
The uxInfiniteScroll directive can be used to manage paging for a scrollable list of
data. Paging can be triggered via a scroll threshold, giving the "infinite scroll" effect, or via
user input. Additionally, the optional uxInfiniteScrollLoading and
uxInfiniteScrollLoadButton directives are provided to display a loading indicator and
a "Load More" button as required.
The uxInfiniteScroll directive has the following configuration properties:
pageNum: number - The index of the requested page, starting from 0.pageSize: number - The number of items requested.filter: any - The filter details as provided via the
filter binding.
pageSize items can be returned, which indicates that the end of the data set has
been reached.
ngFor.
uxInfiniteScroll
directive is defined. To bind to the window scroll the
scrollElement
should be set to
document.documentElement.
preventDefault()
on the event to cancel the load.
Additionally, the following functions can be called on the directive for custom behavior.
The uxInfiniteScrollLoading structural directive can be applied to an element to mark
it as the loading indicator. This will be displayed whenever the infinite scroll directive is
loading data. Note that the loading indicator should be a child of the
uxInfiniteScroll element for this directive to function. The loading and
loaded events are also available to implement more advanced loading indicators.
See below for an example, and note the asterisk prefix to indicate use of a structural directive.
The uxInfiniteScrollLoadButton structural directive can be applied to an element to
mark it as a clickable button which will load a new page of data into the list. This will be
automatically hidden when the control is loading data, or when the data set has been exhausted.
Note that the load button should be a child of the uxInfiniteScroll element for this
directive to function. The request function on uxInfiniteScroll can also
be used to programmatically load pages of data into the list.
See below for an example, and note the asterisk prefix to indicate use of a structural directive.
On the list items, it is important to specify aria-posinset to indicate the position
of the item in the overall collection, and aria-setsize to specify the total number
of items if known (use the value -1 otherwise). Additionally, the example shows use
of
LiveAnnouncer to
announce the start and end of the loading period.