Expand description
Pagination for Leptos.
This crate contains hooks and components for easy pagination of data. It provides efficient loading, caching and displaying of large data. At the same time it is very easy to use even for small datasets.
§Usage
pub struct Book {
title: String,
}
// Implement one of the loader traits for this struct (not shown here, see below).
pub struct BookLoader;
let state = PaginationState::new_store();
view! {
<ul>
<PaginatedFor loader=BookLoader query=() state item_count_per_page=10 let:idx_book>
// idx_book is a tuple containing the index and the book data
<li>{idx_book.1.title.clone()}</li>
</PaginatedFor>
</ul>
<PaginationPrev state>"Prev"</PaginationPrev>
<PaginationNext state>"Next"</PaginationNext>
<nav>
<PaginationPages state />
</nav>
}§Loading data
Loading data is done through implementing one of the various Loader traits. Depending on your use case
you should implement the trait that best fits your needs:
MemoryLoader: If your dataset is already in memory like in aVec,HashSet, array, …PaginatedLoader: If your data source provides data in pages (independent of if you use UI pagination or virtualization).ExactLoader: If your data source can provide an exact range of items (start index to end index).Loader: If none of the above fit your needs, you can implement this trait to provide your own loading logic.
Please refer to the documentation and the examples to see how to implement these traits.
§Components
This crate provides several components designed to help you with the pagination of data. These components are:
PaginatedFor: A component that displays a list of items in a paginated manner.PaginationPages: A component that displays the buttons to jump to a certain page.PaginationNext: A component that displays a button to navigate to the next page.PaginationPrev: A component that displays a button to navigate to the previous page.
Please refer to the examples to see how to use these components.
§Hooks
All components are just thin wrappers that add commonly used html to hook functions that implement the actual logic. So if you want to customize your markup more than what the pre-made components allow you can use these hooks directly.
These are the hooks:
use_pagination: Logic forPaginatedFor. Handles loading items on-demand from the data source and caching them.use_pagination_controls: Logic forPaginationPages. Returns page ranges that can be used to display pagination controls.
If you want to implement your own custom components using these hooks, please have a look at the pre-made components in this crate. You’ll see that there is really nothing special about them.
Modules§
Structs§
- Exact
Loader Marker - Item
Window - This is bascially a signal of a slice of the internal cache.
- Load
Error - Props for the
LoadErrorslot. - Load
Error Builder - Builder for
LoadErrorinstances. - Loaded
Items - Return type of
Loader::load_items. - Loader
Marker - Loading
- Props for the
Loadingslot. - Loading
Builder - Builder for
Loadinginstances. - Memory
Loader Marker - Paginated
ForProps - Props for the
PaginatedForcomponent. - Paginated
Loader Marker - Pagination
Controls - Return type of
use_pagination_controls. It provides a bunch of signals to easily build a pagination component. - Pagination
Next Props - Props for the
PaginationNextcomponent. - Pagination
Pages Props - Props for the
PaginationPagescomponent. - Pagination
Prev Props - Props for the
PaginationPrevcomponent. - Pagination
Range Props - Props for the
PaginationRangecomponent. - Pagination
State - The state of pagination.
- UsePagination
Controls Options - Options for [
use_pagination]. - UsePagination
Options
Enums§
- Paginated
Count - Return type of
PaginatedLoader::count.
Traits§
- Exact
Loader - Trait for loading items on-demand from an data source that let’s you request precise ranges.
- Internal
Loader - This is the trait for the actually used internal loaders. This trait is automatically implemented for all the user facing loader traits.
- Loader
- Loader trait for loading items on-demand from a data source.
- Memory
Loader - Loader trait for loading items on-demand from an in-memory data source.
- Paginated
Loader - Loader trait for loading items on-demand from a paginated data source.
- Pagination
State Store Fields
Functions§
- Paginated
For - Quite similar to Leptos’
<For>this displays a list of items. - Pagination
Next - Button to navigate to the next page.
- Pagination
Pages - A component that renders pagination page controls.
- Pagination
Prev - Button to navigate to the previous page.
- Pagination
Range - Used by
PaginationPagesto render the pagination ranges (button groups). - use_
pagination - Hook for the pagination logic.
- use_
pagination_ controls - Hook for pagination page controls.