I have a field called Elapsed Time (Standard field from Approval Process) in a lightning datatable which is formatted as an alphanumeric string using a helper function. The original data received from the Apex Controller is of Decimal Type.
I need this to be sorted as Minutes > Hours > Days.
I'm using the standard sorting procedure that was provided in the documentation which is working fine for all the other columns.
sortData : function(cmp, fieldName, sortDirection){
var data = cmp.get("v.data");
var reverse = sortDirection !== 'asc';
data = Object.assign([], data.sort(this.sortBy(fieldName, reverse ? -1 : 1)));
cmp.set("v.data", data);
},
sortBy: function (field, reverse, primer){
var key = primer ? function(x){ return primer(x[field]); } : function(x){ return x[field]; };
return function (a, b) {
var A = key(a);
var B = key(b);
return reverse * ((A > B) - (B > A));
};
}