@WidgetComponent

nm-data-list-group-component

File

src/app/shared/widgets/data-list/data-list-component/data-list.group-row.component.ts

Implements

OnInit OnDestroy

Metadata

changeDetection ChangeDetectionStrategy.OnPush
selector nm-data-list-group-component
styles .igx-group-label { padding-left: 1px; }
template
<div class="igx-group-label">
  <igx-checkbox
    [checked]="selectionState == 'all'"
    [indeterminate]="selectionState == 'some'"
    (change)="onChange($event)"
  >
    <span class="nm-label"> {{ columnTitle }}: </span> {{ value }}
  </igx-checkbox>
  &nbsp;&nbsp;<igx-chip displayDensity="compact">{{
    record.records.length
  }}</igx-chip>
</div>

Index

Widget inputs
Widget outputs
Properties
Methods
Inputs
Outputs

Constructor

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

Inputs

grid
record

Outputs

groupSelectionChange $event type: EventEmitter

Methods

ngOnDestroy
ngOnDestroy()
Returns : void
ngOnInit
ngOnInit()
Returns : void
onChange
onChange(event: IChangeCheckboxEventArgs)
Parameters :
Name Type Optional
event IChangeCheckboxEventArgs no
Returns : void
Private updateComponent
updateComponent(selection: any[])
Parameters :
Name Type Optional
selection any[] no
Returns : void
Private updateRecordIds
updateRecordIds()
Returns : void
Private updateRow
updateRow()
Returns : void
Private updateSelection
updateSelection(selection: any[])
Parameters :
Name Type Optional
selection any[] no
Returns : boolean

Properties

Private _grid
_grid: IgxGridComponent
Type : IgxGridComponent
Private _record
_record: IGroupByRecord
Type : IGroupByRecord
Private _recordIds
_recordIds: Set<string>
Type : Set<string>
Private _selectionSubscription
_selectionSubscription: Subscription
Type : Subscription
Public columnTitle
columnTitle: string
Type : string
Public selectionState
selectionState: string
Type : string
Default value : "none"
Public value
value: string
Type : string

Accessors

grid
setgrid(grid: )
Parameters :
Name Optional
grid no
Returns : void
record
getrecord()
setrecord(record: )
Parameters :
Name Optional
record no
Returns : void
import {
  ChangeDetectionStrategy,
  ChangeDetectorRef,
  Component,
  EventEmitter,
  Input,
  Output,
  OnDestroy,
  OnInit,
} from "@angular/core";
import {
  IChangeCheckboxEventArgs,
  IGroupByRecord,
  IgxGridBaseDirective,
  IgxGridComponent,
} from "@infragistics/igniteui-angular";
import { Subscription } from "rxjs";
import { ViewAttributeComponent } from "../../../components/edit-attribute/view-attribute.component";
import { Attributes } from "../../../components/edit-attribute";

@Component({
  selector: "nm-data-list-group-component",
  template: `
    <div class="igx-group-label">
      <igx-checkbox
        [checked]="selectionState == 'all'"
        [indeterminate]="selectionState == 'some'"
        (change)="onChange($event)"
      >
        <span class="nm-label"> {{ columnTitle }}: </span> {{ value }}
      </igx-checkbox>
      &nbsp;&nbsp;<igx-chip displayDensity="compact">{{
        record.records.length
      }}</igx-chip>
    </div>
  `,
  styles: [
    `
      .igx-group-label {
        padding-left: 1px;
      }
    `,
  ],
  changeDetection: ChangeDetectionStrategy.OnPush,
})
export class DataListGroupRowComponent implements OnInit, OnDestroy {
  @Input()
  set grid(grid: IgxGridComponent) {
    this._grid = grid;
    this.updateRecordIds();
  }

  private _grid: IgxGridComponent;

  @Input()
  set record(record: IGroupByRecord) {
    this._record = record;
    this.updateRecordIds();
  }

  @Output()
  groupSelectionChange = new EventEmitter();

  get record(): IGroupByRecord {
    return this._record;
  }

  private _record: IGroupByRecord;
  private _recordIds: Set<string>;
  private _selectionSubscription: Subscription;

  public value: string;
  public columnTitle: string;
  public selectionState: string = "none";

  constructor(private cdr: ChangeDetectorRef) {}

  private updateRecordIds() {
    if (this._grid && this._record) {
      let pk = this._grid.primaryKey;
      let ids = this._record.records.map((row) => row[pk]);
      this._recordIds = new Set(ids);

      this.updateComponent(this._grid.selectedRows);
    }
  }

  private updateComponent(selection: any[]) {
    this.updateSelection(selection);
    this.updateRow();

    this.cdr.detectChanges();
  }

  private updateRow() {
    let fieldName = this._record.expression.fieldName;
    let column = this._grid.getColumnByName(fieldName);
    this.columnTitle = column ? column.header : fieldName;

    let value =
      this._record && this._record.value ? this._record.value : "<empty>";
    value =
      typeof value == "string"
        ? value
        : Attributes.formatAttributeToString(this._record.value);
    this.value = `"${value}"`;
  }

  private updateSelection(selection: any[]): boolean {
    let oldState = this.selectionState;

    let newState = "none";
    if (selection && selection.length > 0) {
      let selectedInGroup = 0;
      selection.forEach((id) => {
        if (this._recordIds.has(id)) {
          selectedInGroup++;
        }
      });

      if (selectedInGroup == this._recordIds.size) {
        newState = "all";
      } else if (selectedInGroup > 0) {
        newState = "some";
      }
    }

    this.selectionState = newState;

    return oldState !== newState;
  }

  onChange(event: IChangeCheckboxEventArgs) {
    let ids = Array.from(this._recordIds.values());
    if (event.checked) {
      this._grid.selectRows(ids);
    } else {
      this._grid.deselectRows(ids);
    }
    this.groupSelectionChange.emit({ newSelection: this._grid.selectedRows });
  }

  ngOnInit(): void {
    this._selectionSubscription = this._grid.rowSelected.subscribe((event) => {
      let selectionChanged = this.updateSelection(event.newSelection);
      if (selectionChanged) {
        this.cdr.markForCheck();
      }
    });
  }

  ngOnDestroy(): void {
    if (this._selectionSubscription) {
      this._selectionSubscription.unsubscribe();
    }
  }
}
Legend
Html element
Component
Html element with directive

results matching ""

    No results matching ""