Skip to content

Instantly share code, notes, and snippets.

@cschuff
Created February 24, 2017 13:26
Show Gist options
  • Save cschuff/3382895b8ea2b39df5a40a5d575b7f44 to your computer and use it in GitHub Desktop.
Save cschuff/3382895b8ea2b39df5a40a5d575b7f44 to your computer and use it in GitHub Desktop.
Sort Comparators for sap.ui.model.Sorter
// ISO Date as string
function (a, b) {
var valA = a.split("T")[0];
var valB = b.split("T")[0];
if (valA < valB) return -1;
if (valA > valB) return 1;
return 0;
};
// string as number
function (a, b) {
var valA = parseInt(a, 10);
var valB = parseInt(b, 10);
if (isNaN(valA)) return 1;
if (isNaN(valB)) return -1;
if (isNaN(valA) && isNaN(valB)) return 0;
return valA - valB;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment