Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

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));
}
Comment

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;
  }
Comment

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>
Comment

PREVIOUS NEXT
Code Example
Javascript :: email id validation in javascript 
Javascript :: which is faster python or node.js for image saving as server 
Javascript :: sequelize findall in array 
Javascript :: function delete localstorage key with prefix 
Javascript :: how to change text in paragraph javascript 
Javascript :: absolute sum javascript 
Javascript :: javascript array group duplicates 
Javascript :: js painting app 
Javascript :: delete all properties from an javascript object 
Javascript :: zoom and pan in d3.js 
Javascript :: Destructing variable assignment 
Javascript :: Calling JSON REST Services with FoxPro and wwJsonServiceClient 
Javascript :: how to cancel placing a block in skript 
Javascript :: how to make password star star on input html 
Javascript :: the caller does not have permission firestore 
Javascript :: go over each line in text nodejs 
Javascript :: idenmnify 
Javascript :: vue-jstree 
Javascript :: cancellable function 
Javascript :: https://social-network.samuraijs.com/article/faq_po_api 
Javascript :: document get all elements by property has white color 
Javascript :: how to draw and expression tree 
Javascript :: random number from 1 to 10000 js 
Javascript :: mocha raise default timeout 
Javascript :: JavaScript Program to illustrate split() function 
Javascript :: npm i react-use-navigator-permissions 
Javascript :: angularjs component stackoverflow 
Javascript :: how to prevent random method from giving more than two same numbers js site:stackoverflow.com 
Javascript :: insert property to many object with prototype 
Javascript :: import lodash react 
ADD CONTENT
Topic
Content
Source link
Name
3+8 =