Angular pipe - Sorting without case sensitive

Allison.A

I got this sorting pipe created in Angular project below. The result is enter image description here I need to sort "Accos, David pt., DIILL," The uppercase seems issue here.

import { Pipe, PipeTransform } from '@angular/core';

@Pipe({
  name: 'orderBy',
})
export class OrderByPipe implements PipeTransform {
  transform(array: any[], field: string): any[] {
    if (!array) return array;

    array = [...array];
    array.sort((a: any, b: any) => {
      if (a[field] < b[field]) {
        return -1;
      } else if (a[field] > b[field]) {
        return 1;
      } else {
        return 0;
      }
    });

    return array;
  }
}
 <ng-select
              [items]="accounts$ | async | orderBy: 'businessName'"
              [(ngModel)]="AccownerId"
              bindLabel="businessName"
              bindValue="id"
              [searchable]="false"
              id="Accowner"
            >
            </ng-select>

artist_dev

You can use this case insensitive comparison:

const options  = ["DIILL", "Accos", "David pt."];
        
options.sort((a: any, b: any) => {
      return a.toLowerCase()
              .localeCompare(b.toLowerCase());
  });
        
console.log(options);//["Accos", "David pt.", "DIILL"]

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Is there a way to compare 2 Strings without it being case-sensitive?

javascript compare strings without being case sensitive

Array contains() without case sensitive lookup?

How to split the String without case-sensitive in java?

Implementing an asynchronous sorting pipe in Angular 2

angular 2 Routes 3.0, case sensitive

restrict 1 word as case sensitive and other as case insensitive in python regex | (pipe)

Case sensitive sorting with capitals last

Custom sorting pipe for Angular 6

MySQL stored procedure query become case sensitive but simple query returns results without case sensitive

Is there a Case-Sensitive Natural-Sorting-Function in Delphi?

Performing a case sensitive string sorting in TypeScript

Jquery filter list without case sensitive

Highlight keyword without case sensitive?

Non case-sensitive sorting in dojo dgrid

Sort behaves strangely on case sensitive sorting

javascript - check if string is in a array without case sensitive

Accessing a path which case sensitive without writing so

base href is case sensitive in Angular 2

Is Angular 2/4 really case sensitive?

Angular: Are template components case sensitive

Angular Custom Order Pipe sorting array correctly

Sorting case sensitive array not working in C

SQLite using GROUP BY without being case sensitive

ICU: demonstrate case-sensitive sorting

Swift non-case sensitive dictionary sorting

Angular currency pipe without value

Is it possible to use `if … in` to search through an object without it being case-sensitive?

Is Java case-sensitive string sorting broken?