BaseListComponent
BaseListComponent
This is a base class which implements the logic required to fetch and manipulate a list of data from a query which returns a PaginatedList type.
It is normally used in combination with the DataTable2Component.
Signature
class BaseListComponent<ResultType, ItemType, VariableType extends Record<string, any> = any> implements OnInit, OnDestroy {
searchTermControl = new FormControl('');
selectionManager = new SelectionManager<any>({
multiSelect: true,
itemsAreEqual: (a, b) => a.id === b.id,
additiveMode: true,
});
result$: Observable<ResultType>;
items$: Observable<ItemType[]>;
totalItems$: Observable<number>;
itemsPerPage$: Observable<number>;
currentPage$: Observable<number>;
protected protected destroy$ = new Subject<void>();
protected protected refresh$ = new BehaviorSubject<undefined>(undefined);
constructor(router: Router, route: ActivatedRoute)
setQueryFn(listQueryFn: ListQueryFn<ResultType>, mappingFn: MappingFn<ItemType, ResultType>, onPageChangeFn?: OnPageChangeFn<VariableType>, defaults?: { take: number; skip: number }) => ;
protected refreshListOnChanges(streams: Array<Observable<any>>) => ;
setPageNumber(page: number) => ;
setItemsPerPage(perPage: number) => ;
refresh() => ;
protected setQueryParam(hash: { [key: string]: any }, options?: { replaceUrl?: boolean; queryParamsHandling?: QueryParamsHandling }) => ;
protected setQueryParam(key: string, value: any, options?: { replaceUrl?: boolean; queryParamsHandling?: QueryParamsHandling }) => ;
protected setQueryParam(keyOrHash: string | { [key: string]: any }, valueOrOptions?: any, maybeOptions?: { replaceUrl?: boolean; queryParamsHandling?: QueryParamsHandling }) => ;
}
Implements
- OnInit
- OnDestroy
Members
searchTermControl
property
type:
selectionManager
property
type:
result$
property
type:
Observable<ResultType>
items$
property
type:
Observable<ItemType[]>
totalItems$
property
type:
Observable<number>
itemsPerPage$
property
type:
Observable<number>
currentPage$
property
type:
Observable<number>
destroy$
property
type:
refresh$
property
type:
constructor
method
type:
(router: Router, route: ActivatedRoute) => BaseListComponent
setQueryFn
method
type:
(listQueryFn: ListQueryFn<ResultType>, mappingFn: MappingFn<ItemType, ResultType>, onPageChangeFn?: OnPageChangeFn<VariableType>, defaults?: { take: number; skip: number }) =>
Sets the fetch function for the list being implemented.
refreshListOnChanges
method
type:
(streams: Array<Observable<any>>) =>
Accepts a list of Observables which will trigger a refresh of the list when any of them emit.
setPageNumber
method
type:
(page: number) =>
Sets the current page number in the url.
setItemsPerPage
method
type:
(perPage: number) =>
Sets the number of items per page in the url.
refresh
method
type:
() =>
Re-fetch the current page of results.
setQueryParam
method
type:
(hash: { [key: string]: any }, options?: { replaceUrl?: boolean; queryParamsHandling?: QueryParamsHandling }) =>
setQueryParam
method
type:
(key: string, value: any, options?: { replaceUrl?: boolean; queryParamsHandling?: QueryParamsHandling }) =>
setQueryParam
method
type:
(keyOrHash: string | { [key: string]: any }, valueOrOptions?: any, maybeOptions?: { replaceUrl?: boolean; queryParamsHandling?: QueryParamsHandling }) =>