Skip to content

Instantly share code, notes, and snippets.

@cuneydbolukoglu
Created March 16, 2022 09:10
Show Gist options
  • Save cuneydbolukoglu/cda4ed9ee18f763e61448c501866d1c8 to your computer and use it in GitHub Desktop.
Save cuneydbolukoglu/cda4ed9ee18f763e61448c501866d1c8 to your computer and use it in GitHub Desktop.
Input Filter Search Antdesign library 3.x
/**
* Order function by key.
* @default "asc"
* data => field to order (Object, List, Array).
* key => the data to be order by this key.
*/
function orderListByKey(data, key, order) {
const compareValues = (key, order = "asc") => (elemA, elemB) => {
if (!elemA.hasOwnProperty(key) || !elemB.hasOwnProperty(key)) return 0;
const comparison = elemA[key].localeCompare(elemB[key]);
return order === "desc" ? comparison * -1 : comparison;
};
return data.sort(compareValues(key, order));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment