I'm trying to use the mat-sort to order one mat-table in angular, the problem is when i order in ascendent/decrescent order, the algoritm order capitalized words first than uncapitalized. If i have one table with this names:
"Mark" "antony"
"Mark" shows first than antony.
This is the algoritm:
sortData(sort: Sort) {
const data = this.descricoesProdutos.slice();
if (!sort.active || sort.direction === '') {
this.sortedData = data;
return;
}
this.sortedData = data.sort((a, b) => {
const isAsc = sort.direction === 'asc';
switch (sort.active) {
case 'nome': return this.compare(a.nome, b.nome, isAsc);
case 'descricao': return this.compare(a.descricao, b.descricao, isAsc);
default: return 0;
}
});
}
compare(a: number | string, b: number | string, isAsc: boolean) {
return (a < b ? -1 : 1) * (isAsc ? 1 : -1);
}
My html:
<table matSort (matSortChange)="sortData($event)">