Angular Material Table Alphanumeric Sorting Behaviour
This isn't the best solution for this, but I created a short and sweet workaround for this. Using the sort
predicate function of the array
.
// Following the example to the question
financingPurposeList.sort(function(a, b){
return a.code.length - b.code.length;
});
You can do something like this.
var collator = new Intl.Collator(undefined, {numeric: true, sensitivity: 'base'});
var myArray = ['F1',
'F10',
'F2',
'F5',
'F9'];
console.log(myArray.sort(collator.compare));
You can achieve that by adding sort function after getting the data.
usage:
ngOnInit() {
this.dataSource.data.sort((a, b) => (a.code- b.code) );
}