File

core/common/forOf.directive.ts

Description

A directive to iterate over IResultList data from @c8y/client. Depending on the [c8yForLoadMore] a load more button is:

  • auto: Tries to automatically load more data (default maximum 10 iterations; can be change with maxIterations settings).
  • show: Shows a load more button for the user to decide
  • none: Doesn't perform any load more action.
  • hidden: Loads more data automatically but with no visible button for the user.

Additional, any rxjs operator pipe can be applied to the [c8yForPipe] input, e.g. to filter the data displayed currently as well as the data loaded by subsequent requests.

Example :
<div *c8yFor="let device of devices; loadMore: 'auto'; let i = index; pipe: filterPipe;">
 {{ i + 1 }}. {{device.name}}
</div>

The above example will list all entities that are applied to devices:

Example :
this.devices = this.inventoryService.list({ pageSize: 10, fragmentType: 'c8y_IsDevice' })

It will display the first 10 items, if there is more space left on the screen, and there are more than 10 devices, it will automatically load up to 10 pages more. If it still can't fit the screen it will stop and switch to show mode.

A pipe can be applied e.g. for filtering or grouping. This pipe is attached to every follow up request done by the load more component:

Example :
this.filterPipe = pipe(
   map((data: []) => {
    return data.filter(
     (mo: any) => mo.name && mo.name.toLowerCase().indexOf(value.toLowerCase()) > -1
   );
 })
);

The pipe must be an rxjs pipe and can take any operator.

Example with realtime support and items count output (e.g. for handling empty state and header):

Example :
<c8y-list-group>
  <div class="c8y-empty-state" *ngIf="count === 0">
    (...)
  </div>

  <div class="page-sticky-header hidden-xs c8y-list__item c8y-list--timeline" *ngIf="count > 0">
    (...)
  </div>

  <ng-template
    c8yFor
    let-operation
    [c8yForOf]="items$"
    [c8yForPipe]="filterPipe"
    [c8yForRealtime]="realtime"
    [c8yForRealtimeOptions]="realtimeOptions"
    (c8yForCount)="count = $event"
  >
    <c8y-li-timeline>
      (...)
    </c8y-li-timeline>
  </ng-template>
</c8y-list-group>
Example :
@Component({
  (...)
})
export class ExampleComponent {
  @Input() deviceId: IIdentified;
  items$ = this.operationService.list({
    deviceId: this.deviceId,
    fragmentType: 'c8y_MyOperation',
    dateFrom: new Date(0).toISOString(),
    dateTo: new Date(Date.now()).toISOString(),
    revert: true,
    withTotalPages: true
  });
  filterPipe = pipe(map((ops: IOperation[]) => ops.filter(op => op.c8y_MyOperation)));
  realtimeOptions: ForOfRealtimeOptions = {
    entityOrId: this.deviceId,
    removeOnUpdate: true,
    insertOnUpdate: true
  } as ForOfRealtimeOptions;
  count: number;

  constructor(
    private operationService: OperationService,
    public realtime: OperationRealtimeService
  ) {}
}

Metadata

Index

Methods
Inputs
Outputs
Accessors

Constructor

constructor(tpl: TemplateRef, vcr: ViewContainerRef, cdRef: ChangeDetectorRef)
Parameters :
Name Type Optional
tpl TemplateRef<any> No
vcr ViewContainerRef No
cdRef ChangeDetectorRef No

Inputs

c8yForComparator

A comparator function for comparing list items. Used to determine the position at which a new element should be added to the list.

c8yForEnableVirtualScroll
Type : boolean
Default value : false

Enable virtual scroll rendering method.

c8yForLoadingLabel
Type : string

Loading text label.

c8yForLoadingTemplate

A custom loading component.

c8yForLoadMore

The mode setter:

  • auto: Tries to automatically load more data (default maximum 10 iterations; can be change with maxIterations settings).
  • show: Shows a load more button for the user to decide
  • none: Doesn't perform any load more action.
  • hidden: Loads more data automatically but with no visible button for the user.
c8yForLoadNextLabel
Type : string

Load next text label.

c8yForMaxIterations
Type : number

The maximum numbers of iterations to call data from the api.

c8yForNotFound

A template to use if no data is found at all (e.g. if you apply a filter pipe).

c8yForOf
Type : IResultList | Observable

The data setter. Must be a response from @c8y/data or an observable. You can pass an observable with null to explicitly clear the list.

c8yForPipe

The pipe setter to attach any rxjs pipe to the current and more loaded data.

c8yForRealtime

A RealtimeService instance.

c8yForRealtimeOptions

Realtime options.

c8yForVirtualScrollContainerHeight
Type : number

When used fixed strategy, there needs to be fixed height set on scrolling container.

c8yForVirtualScrollElementSize
Type : any

Provides fixed item size for virtual scroll window strategy.

c8yForVirtualScrollStrategy
Type : "fixed" | "window"
Default value : 'window'

Sets mode of virtual scroller instance. window is used for case when whole viewport is scrolled. fixed can be used on inner-scroll containers.

Outputs

c8yForChange
Type : EventEmitter

The items change event emitting the newly loaded items.

Note: This can only be used if the forOf isn't used with the sugared asterisk (*) syntax. Instead you need to use an ng-template:

Example :
<ng-template
 c8yFor
 let-operation
 [c8yForOf]="operations$"
 (c8yForChange)="onChangeForOf($event)"
>
</ng-template>
c8yForCount
Type : EventEmitter

The number of items currently loaded in the list.

Note: This can only be used if the forOf isn't used with the sugared asterisk (*) syntax. Instead you need to use an ng-template:

Example :
<ng-template
 c8yFor
 let-operation
 [c8yForOf]="operations$"
 (c8yForCount)="operationCount = $event"
>
</ng-template>
c8yForLoadMoreComponent
Type : EventEmitter

The current instance of the LoadMoreComponent.

Methods

ngOnChanges
ngOnChanges(changes: SimpleChanges)
Parameters :
Name Type Optional
changes SimpleChanges No
Returns : void
ngOnDestroy
ngOnDestroy()
Returns : void
ngOnInit
ngOnInit()
Returns : void

Accessors

c8yForOf
setc8yForOf(fetchData: IResultList | Observable>)

The data setter. Must be a response from @c8y/data or an observable. You can pass an observable with null to explicitly clear the list.

Parameters :
Name Type Optional
fetchData IResultList<IIdentified> | Observable<IResultList<IIdentified>> No
Returns : void
c8yForLoadMore
setc8yForLoadMore(type)

The mode setter:

  • auto: Tries to automatically load more data (default maximum 10 iterations; can be change with maxIterations settings).
  • show: Shows a load more button for the user to decide
  • none: Doesn't perform any load more action.
  • hidden: Loads more data automatically but with no visible button for the user.
Parameters :
Name Optional
type No
Returns : void
c8yForPipe
setc8yForPipe(dataPipe)

The pipe setter to attach any rxjs pipe to the current and more loaded data.

Parameters :
Name Optional
dataPipe No
Returns : void
c8yForNotFound
setc8yForNotFound(notFoundTemplate)

A template to use if no data is found at all (e.g. if you apply a filter pipe).

Parameters :
Name Optional
notFoundTemplate No
Returns : void
c8yForMaxIterations
setc8yForMaxIterations(maxIterations: number)

The maximum numbers of iterations to call data from the api.

Parameters :
Name Type Optional
maxIterations number No
Returns : void
c8yForLoadingTemplate
setc8yForLoadingTemplate(loadingTemplate)

A custom loading component.

Parameters :
Name Optional
loadingTemplate No
Returns : void
c8yForLoadNextLabel
setc8yForLoadNextLabel(loadNextLabel: string)

Load next text label.

Parameters :
Name Type Optional
loadNextLabel string No
Returns : void
c8yForLoadingLabel
setc8yForLoadingLabel(loadingLabel: string)

Loading text label.

Parameters :
Name Type Optional
loadingLabel string No
Returns : void
c8yForRealtime
setc8yForRealtime(source)

A RealtimeService instance.

Parameters :
Name Optional
source No
Returns : void
c8yForRealtimeOptions
setc8yForRealtimeOptions(realtimeOptions)

Realtime options.

Parameters :
Name Optional
realtimeOptions No
Returns : void
c8yForComparator
setc8yForComparator(comparator)

A comparator function for comparing list items. Used to determine the position at which a new element should be added to the list.

Parameters :
Name Optional
comparator No
Returns : void

results matching ""

    No results matching ""