0

In my application I have an API that contains different objects. I am displaying data on front end. I am successfully able to sort strings using following code

.ts file

sort(username: string) {
    if (username !== this.findQuery.sortusername) {
      this.findQuery.sortusername = username;
      this.findQuery.sortOrder = 'asc';
    } else {
      this.findQuery.sortOrder = this.findQuery.sortOrder === 'asc' ? 'desc' : 'asc';
    }
  }

.html file

  <th (click)="sort('username')" scope="col" class="link">Username
      <span *ngIf="findQuery.sortusername==='username'">
        <search-sort [sortOrder]="findQuery.sortOrder"></search-sort>
      </span>
    </th>

I am having difficulty to sort Integer object for below quantity field

.html

  <th *ngIf="searchViewSettings?.fields?.quantity" (click)="sortQuantity('supplemental.quantity.keyword')" scope="col" class="link">Quantity
      <span *ngIf="findQuery.sortField==='supplemental.quantity.keyword'">
        <search-sort [sortOrder]="findQuery.sortOrder"></search-sort>
      </span>
    </th>

Note Quantity column contains numbers or N/A as data

Example - Quantity column 1, 44, N/A, 455, 12, 8, N/A for each row displayed

A Aama
  • 31
  • 5
  • Can you show the contents of the `sortQuantity ` function? – Kinglish May 18 '21 at 22:25
  • I was able to write logic for string, but not numbers. I am struggling with that, any help is appreciated. Thanks @Kinglish – A Aama May 18 '21 at 22:29
  • Do you mean to reorder a list based on the Quantity column? If so, you need a pipe - here is a good guide: https://stackoverflow.com/a/35465976/1772933 – Kinglish May 18 '21 at 22:34

0 Answers0