Answers for "order by ascending descending in angular 6 on click of button"

0

order by ascending descending in angular 6 on click of button

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;
  }
Posted by: Guest on July-06-2021
0

order by ascending descending in angular 6 on click of button

<button (click)="sortData()">Sort Data</button>
<div *ngFor="let item of items">
{{items.attributes.fullName}}
</div>
Posted by: Guest on July-06-2021
0

order by ascending descending in angular 6 on click of button

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));
}
Posted by: Guest on July-06-2021

Code answers related to "order by ascending descending in angular 6 on click of button"

Code answers related to "Javascript"

Browse Popular Code Answers by Language