“Ordem por descer ascendentes no Angular 6 no clique do botão” Respostas de código

Ordem por descer ascendentes no Angular 6 no clique do botão

private isAscendingSort: boolean = false;

sortUser() {
  console.log('sorting!'); // just to check if sorting is being called
  this.isAscendingSort = !this.isAscendingSort; // you missed this

  this.items.sort((item1: any, item2: any) => this.compare(item1, item2));
}
Precious Puffin

Ordem por descer ascendentes no Angular 6 no clique do botão

<button (click)="sortData()">Sort Data</button>
<div *ngFor="let item of items">
{{items.attributes.fullName}}
</div>
Precious Puffin

Ordem por descer ascendentes no Angular 6 no clique do botão

let isAscendingSort: Boolean = true;
sortUser() {
    console.log('sorting!'); //just to check if sorting is beng called
    this.items.sort((item1: any, item2: any) => this.compare(item1, item2));
  }
  // Sort
  compare(item1: any, item2: any): number {
    let compValue = 0;
      compValue = item1.attributes.fullName.localeCompare(item2.attributes.fullName, 'en', {
        sensitivity: 'base'
      });
    console.log(compValue);
    if (!this.isAscendingSort) {
      compValue = compValue * -1;
    }
    return compValue;
  }
Precious Puffin

Respostas semelhantes a “Ordem por descer ascendentes no Angular 6 no clique do botão”

Perguntas semelhantes a “Ordem por descer ascendentes no Angular 6 no clique do botão”

Mais respostas relacionadas para “Ordem por descer ascendentes no Angular 6 no clique do botão” em JavaScript

Procure respostas de código populares por idioma

Procurar outros idiomas de código