'How to sort data in other language characters in angular material table?
For example in turkish we have some special characters like 'ç ,ğ, ö' etc. And I want to be able to sort with them. Is it possible? Thanks for any help.
Solution 1:[1]
Sort order is determined doing a lexicographical sort by comparing the Unicode. This article offers you two solution for your problem: check it out
Solution 2:[2]
Specifying the collation changes the result. I faced the same problem and I solved it like this:
import { Pipe, PipeTransform } from '@angular/core';
@Pipe({
name: 'orderBy'
})
export class OrderByPipe implements PipeTransform {
transform(array: any, field: string, isAscending: boolean): any[] {
if (isAscending) {
array.sort((a: any, b: any) =>
a[field].localeCompare(b[field], 'tr'));
return array;
} else {
array.sort((a: any, b: any) =>
b[field].localeCompare(a[field], 'tr'));
return array;
}
}
}
Here is the usage:
<div class="col-lg-6" *ngFor="let entity of entities$ | orderBy: 'name' : true">
I hope this solution works for you.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Jánosi-Borsos Róbert |
| Solution 2 | Emre |
