I have a problem sorting my columns with angular material mat-sort.
I have some codes called correlative_request
which were assigned with letters, numbers and characters. Here the problem is that when I try to sort my table in ascending order I would expect it to start counting in the following way
B-23-3-01 B-23-3-02 B-23-3-03 .... B-23-3-029
But instead of doing it like this, it does it by taking the minors and then the majors something like this:
B-23-3-01 B-23-3-010 B-23-3-011 .... B-23-3-02 B-23-3-020 .... B-23-3-029
I made a small demo of how I have it in my project, to replicate my error, in my project I use component inheritance to pass the dataSource to my table but that does not interfere with the sort itself. Demo In Stackblitz
I tried the following function to order the correlatives or alphanumeric codes, but even so I did not achieve what I want because it returns ['B-23-3-0', 'B-23-3-02', 'B-23-3 -029', 'B-23-3-03'] and I expected it to return ['B-23-3-0', 'B-23-3-02', 'B-23-3-03' , 'B-23-3-029']
/* order array [B-23-3-0, B-23-3-02, B-23-3-03, B-23-3-029] from smallest to largest */
var array = ['B-23-3-0', 'B-23-3-02', 'B-23-3-03', 'B-23-3-029'];
array.sort(function(a, b) {
return a.localeCompare(b);
});
console.log('array sort', array);
If someone helps me I would be grateful, I leave you some images of what the jump of the numbers looks like when I try to order them
I tried some of the solutions that I found in stack but they did not work for me, I attach the link of the question that I found and some of the answers I tried Angular Material Table Alphanumeric Sorting Behaviour