File

projects/storefrontlib/shared/components/list-navigation/sorting/sorting.component.ts

Metadata

changeDetection ChangeDetectionStrategy.OnPush
selector cx-sorting
templateUrl ./sorting.component.html

Index

Properties
Methods
Inputs
Outputs
Accessors

Constructor

constructor()

Inputs

placeholder
Type : string
selectedOption
Type : string
sortLabels
Type : literal type
sortOptions
Type : SortModel[]

Outputs

sortListEvent
Type : EventEmitter<string>

Methods

sortList
sortList(sortCode: string)
Parameters :
Name Type Optional
sortCode string No
Returns : void

Properties

placeholder
Type : string
Decorators :
@Input()
selectedOption
Type : string
Decorators :
@Input()
sortLabels
Type : literal type
Decorators :
@Input()
sortListEvent
Type : EventEmitter<string>
Decorators :
@Output()
sortOptions
Type : SortModel[]
Decorators :
@Input()

Accessors

selectedLabel
getselectedLabel()
import {
  ChangeDetectionStrategy,
  Component,
  EventEmitter,
  Input,
  Output,
} from '@angular/core';
import { SortModel } from '@spartacus/core';

@Component({
  selector: 'cx-sorting',
  templateUrl: './sorting.component.html',
  changeDetection: ChangeDetectionStrategy.OnPush,
})
export class SortingComponent {
  @Input()
  sortOptions: SortModel[];
  @Input()
  selectedOption: string;
  @Input()
  placeholder: string;
  @Input()
  sortLabels: { [code: string]: string };

  @Output()
  sortListEvent: EventEmitter<string>;

  constructor() {
    this.sortListEvent = new EventEmitter<string>();
  }

  sortList(sortCode: string): void {
    this.sortListEvent.emit(sortCode);
  }

  get selectedLabel() {
    return (
      this.sortOptions?.find((sort) => sort.code === this.selectedOption)
        ?.name ?? this.sortLabels?.[this.selectedOption]
    );
  }
}
<ng-select
  [searchable]="false"
  [clearable]="false"
  placeholder="{{ placeholder }}"
  (change)="sortList($event)"
  [ngModel]="selectedOption"
  [attr.aria-label]="selectedLabel || placeholder"
>
  <ng-option *ngFor="let sort of sortOptions" [value]="sort.code">{{
    sort.name ? sort.name : sortLabels ? sortLabels[sort.code] : ''
  }}</ng-option>
</ng-select>
Legend
Html element
Component
Html element with directive

result-matching ""

    No results matching ""