the default sort of ng-grid is not alphanumeric. is it possible to apply a custom sort function in order to obtain a correct sort, as :
'11' '2' 'eé' 'ed' => '2' '11' 'ed' 'eé'
You could define your own sorting function.
Here's an example with your data. (Fixed it using Devin Torres' Natural Sorting algorithm)
var myAwesomeSortFn = function(a,b){
var NUMBER_GROUPS = /(-?\d*\.?\d+)/g;
var myAwesomeSortFn = function(a, b) {
var aa = String(a).split(NUMBER_GROUPS),
bb = String(b).split(NUMBER_GROUPS),
min = Math.min(aa.length, bb.length);
for (var i = 0; i < min; i++) {
var x = parseFloat(aa[i]) || aa[i].toLowerCase(),
y = parseFloat(bb[i]) || bb[i].toLowerCase();
if (x < y) return -1;
else if (x > y) return 1;
}
return 0;
};
$scope.myData = [{name: "Moroni", age: 11},
{name: "Tiancum", age: 2},
{name: "Jacob", age: 'eé'},
{name: "Nephi", age: 'ed'}];
$scope.gridOptions = {
data: 'myData',
columnDefs: [{field: 'name', displayName: 'Name'}, {field:'age', displayName:'Age', sortFn: myAwesomeSortFn}]
};
sortingAlgorithm instead of sortFn.Here is what I have so far:
$scope.links = {
sortFun: function(a, b) { console.log('a:' + a + ', b: ' + b); }
};
...
$scope.data.grid.columnDefs.push(
{'field': key, 'sortingAlgorithm': $scope.links.sortFun }
);
...
$scope.data.grid.columnDefs.push({'field': key, 'sortingAlgorithm': $scope.links.sortFun });