Created
August 23, 2021 15:17
-
-
Save isaaclyman/0918d62ee38509b15c2502277856cfdc to your computer and use it in GitHub Desktop.
JavaScript sort by multiple fields
This file contains hidden or 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
rows.sort((a, b) => { | |
const amountTypeSort = a.amountType.localeCompare(b.amountType); | |
if (amountTypeSort !== 0) { | |
return amountTypeSort; | |
} | |
const laborCostTypeDisplayNameSort = a.costTypeDisplayName.localeCompare(b.costTypeDisplayName); | |
if (laborCostTypeDisplayNameSort !== 0) { | |
return laborCostTypeDisplayNameSort; | |
} | |
const laborCostTypeNameSort = a.costTypeName.localeCompare(b.costTypeName); | |
if (laborCostTypeNameSort !== 0) { | |
return laborCostTypeNameSort; | |
} | |
const timeframeNumberSort = a.costTypeTimeframeNumber - b.costTypeTimeframeNumber; | |
return timeframeNumberSort; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment