Options
All
  • Public
  • Public/Protected
  • All
Menu

Class MediatedTableComponent<F, O>

This component reduces all boilerplate code to the absolut minimum:

  • defining the columns: columns = ['name', 'age'];
  • defining the used mediator class: constructor() { super(SimpleTableMediator); }
  • implementing the fetch function: return this.http.get('my-endpoint');

It exposes the mediator instance, so you may hook into its events.

Type parameters

  • F

    type of the trigger payload to be used in the underlying fetch function, for example a form output

  • O

    type of the output data for the table. This must match MatTable's generic type

Hierarchy

  • MediatedTableComponent

Implements

  • AfterViewInit
  • OnDestroy

Index

Constructors

Protected constructor

  • The initialIsLoading param sets the initial value for isLoading$. If your fetching (read: loading) starts in start and the initial value for isLoading$ is false, you will get an ExpressionChangedAfterItHasBeenCheckedError! Use this parameter to prevent this error.

    Parameters

    • Default value initialIsLoading: boolean = true

      the initial value for isLoading$

    • Default value mediatorClass: Newable<MatTableMediator<F, O>> = SimpleTableMediator

      Class of the Mediator to use

    Returns MediatedTableComponent

Properties

Abstract columns

columns: Columns<O>

array of column ids. Has to match the keys of your data interface

typeparam

type of table data

isLoading$

isLoading$: Observable<boolean>

Observable for the current loading status. Will be pre-initialised in the constructor, to prevent ExpressionChangedAfterItHasBeenCheckedError

mediator

mediator: MatTableMediator<F, O>

the mediator instance, initialised in the initMediator() method

Private mediatorClass

mediatorClass: Newable<MatTableMediator<F, O>>

Class of the Mediator to use

mediatorConfig

mediatorConfig: Partial<MediatorConfig<O>>

the config object for the mediator

Optional paginator

paginator: MatPaginator

Queried @ViewChild paginator, may be undefined if no paginator is in the template

Optional sort

sort: MatSort

Queried @ViewChild sort directive, may be undefined if no sort is in the template

table

table: MatTable<O>

Queried @ViewChild table element

trigger$

trigger$: TriggerPayload<F> = of(undefined)

trigger$ Observable of type <F>. Defaults to immediately emitting undefined, via of

Methods

Abstract fetch

  • fetch(payload?: F, sortBy?: Column<O>, sortDirection?: SortDirection, pageIndex?: number, pageSize?: number): Observable<MediatorData<O>>
  • The fetch method that will be used by the mediator

    Parameters

    • Optional payload: F

      the latest payload of the trigger$ observable

    • Optional sortBy: Column<O>

      the current column id that is sorted by

    • Optional sortDirection: SortDirection

      the current sort direction

    • Optional pageIndex: number

      the current page index

    • Optional pageSize: number

      the current page size

    Returns Observable<MediatorData<O>>

initMediator

  • initMediator(): void
  • Initialises the mediator instance. By default this will be called automatically with the ngAfterViewInit method. It sets this.isLoading$ observable to the mediator.isLoading$ observable.

    Returns void

initMediatorAsync

  • initMediatorAsync(): Promise<void>
  • Wrapper to initialise the mediator in an async fashion. This may be used to prevent ExpressionChangedAfterItHasBeenCheckedError in some cases. Overwrite the ngAfterViewInit method and call this method.

    Returns Promise<void>

ngAfterViewInit

  • ngAfterViewInit(): void

ngOnDestroy

  • ngOnDestroy(): void

Generated using TypeDoc