File

packages/ui/src/lib/list/list-items/list-items.component.ts

Description

The ListItemsComponent displays the actual list, without all peripherals (header, pagination etc.). It can either be given an Array of Items or just the list parent to control the shown items.

Implements

OnChanges

Metadata

changeDetection ChangeDetectionStrategy.OnPush
selector ec-list-items
templateUrl ./list-items.component.html

Index

Properties
Methods
Inputs
Outputs

Constructor

constructor(cdr: ChangeDetectorRef)
Parameters :
Name Type Optional
cdr ChangeDetectorRef No

Inputs

focusItem
Type : Item<T>

The current focused item

items
Type : Item<T>[]

An Optional Array of Item's that should be displayed. If none are provded, the list Items are used.

list
Type : List<T>

The list instance

selection
Type : Selection<T>

The selection instance. This is optional. If It is not provided, no checkbox will be visible.

solo
Type : boolean

If true, only one item is selectable next

Outputs

columnClicked
Type : EventEmitter<Item<T>>

Event emitter on item clicked

Methods

columnClick
columnClick(item: Item, e: Event)

Propagate clicked item to host or toggle selection.

Parameters :
Name Type Optional
item Item<T> No
e Event No
Returns : void
hasFocus
hasFocus(item)

yields true if the item is focussed

Parameters :
Name Optional
item No
Returns : boolean
isClickable
isClickable()
Returns : any
ngOnChanges
ngOnChanges()

Checks for host and uses its list.

Returns : void

Properties

Public cdr
Type : ChangeDetectorRef
import { Component, Input, Output, EventEmitter, ChangeDetectionStrategy, ChangeDetectorRef } from '@angular/core';
import { Item, List, Selection } from '@ec.components/core';
import { OnChanges } from '@angular/core';

/** The ListItemsComponent displays the actual list, without all peripherals (header, pagination etc.).
 * It can either be given an Array of Items or just the list parent to control the shown items. */
@Component({
  selector: 'ec-list-items',
  templateUrl: './list-items.component.html',
  changeDetection: ChangeDetectionStrategy.OnPush,
})
export class ListItemsComponent<T> implements OnChanges {
  /** The list instance */
  @Input() list: List<T>;
  /** The selection instance. This is optional. If It is not provided, no checkbox will be visible.*/
  @Input() selection: Selection<T>;
  /** An Optional Array of Item's that should be displayed. If none are provded, the list Items are used.*/
  @Input() items: Item<T>[];
  /** If true, only one item is selectable next */
  @Input() solo: boolean;
  /** The current focused item */
  @Input() focusItem: Item<T>;
  /** Event emitter on item clicked */
  @Output() columnClicked: EventEmitter<Item<T>> = new EventEmitter();

  constructor(public cdr: ChangeDetectorRef) { }
  /** Checks for host and uses its list. */
  ngOnChanges() {
    if (!this.items && this.list) {
      this.items = this.list.page;
    }
    if (this.list) {
      this.list.change$.subscribe((newList) => {
        this.cdr.markForCheck();
      });
    }
    if (this.selection) {
      this.selection.update$.subscribe((newList) => {
        this.cdr.markForCheck();
      });
    }
  }
  /** yields true if the item is focussed */
  hasFocus(item) {
    return this.focusItem === item;
  }

  isClickable() {
    return this.columnClicked.observers.length || (this.selection && this.list && this.list.config.selectMode);
  }

  /** Propagate clicked item to host or toggle selection. */
  columnClick(item: Item<T>, e: Event) {
    e.stopPropagation();
    e.stopImmediatePropagation();
    if (this.selection && this.list && this.list.config.selectMode) {
      this.selection.toggle(item, this.solo);
    } else if (this.columnClicked.observers.length) {
      this.columnClicked.emit(item);
    }
  }
}
<ul class="ec-list-items">
  <li
    *ngFor="let item of items; trackBy: list?.trackItem"
    (click)="columnClick(item, $event)"
    class="ec-list-item"
    [ngClass]="item.classes()"
    [class.is-clickable]="isClickable()"
    [class.is-focus]="hasFocus(item)"
    [class.is-selected]="selection?.has(item)"
  >
    <div
      class="ec-list-cell ec-list-item__selector"
      *ngIf="list?.config?.selectMode"
    >
      <input type="checkbox" [checked]="selection?.has(item)" />
    </div>
    <div
      *ngFor="let field of list?.fields; let i = index"
      class="ec-list-cell"
      [ngClass]="'ec-list-cell_' + field.getView('output') + ' ' + (field.classes || '') +' ec-list-field_' + field.property"
      [class.is-hidden]="field.hideInList"
      [class.is-sortable]="field.sortable"
      [class.is-filtered]="list.isFiltered(field.property)"
      [class.is-sorted]="list.config?.sortBy === field.property"
    >
      <ec-output
        [field]="field"
        [item]="item"
        [component]="field.getComponent('list') || field.output"
      ></ec-output>
    </div>
  </li>
</ul>
Legend
Html element
Component
Html element with directive

result-matching ""

    No results matching ""