Working with Lists
ListService
is a utility service to provide easy pagination, sorting, and search implementation.
Getting Started
ListService
is not provided in root. The reason is, this way, it will clear any subscriptions on component destroy. You may use the optional LIST_QUERY_DEBOUNCE_TIME
token to adjust the debounce behavior.
Noticed
list
ispublic
andreadonly
? That is because we will useListService
directly in the component's template. That may be considered as an anti-pattern, but it is much quicker to implement. You can always use public component members to expose theListService
instance instead.
Bind ListService
to ngx-datatable like this:
Extending query with custom variables
You can extend the query parameter of the ListService
's hookToQuery
method.
Firstly, you should pass your own type to ListService
as shown below:
Then update the bookStreamCreator
constant like following:
You can also create your params object.
Define a variable like this:
Update the bookStreamCreator
constant:
Then you can place inputs to the HTML:
ListService
emits the hookToQuery stream when you call the this.list.get()
method.
Usage with Observables
You may use observables in combination with AsyncPipe of Angular instead. Here are some possibilities:
...or...
We do not recommend using the NGXS store for CRUD pages unless your application needs to share list information between components or use it later on in another page.
How to Refresh Table on Create/Update/Delete
ListService
exposes a get
method to trigger a request with the current query. So, basically, whenever a create, update, or delete action resolves, you can call this.list.get();
and it will call hooked stream creator again.
...or...
We do not recommend using the NGXS store for CRUD pages unless your application needs to share list information between components or use it later on in another page.
How to Implement Server-Side Search in a Table
ListService
exposes a filter
property that will trigger a request with the current query and the given search string. All you need to do is to bind it to an input element with two-way binding.
ABP doesn't have a built-in filtering mechanism. You need to implement it yourself and handle the filter
property in the backend.