Created
March 16, 2022 09:10
-
-
Save cuneydbolukoglu/cda4ed9ee18f763e61448c501866d1c8 to your computer and use it in GitHub Desktop.
Input Filter Search Antdesign library 3.x
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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