Files
vault/ui/app/utils/sort-objects.js
Chelsea Shaw 8d2ae17dae UI: helper sort-objects to alphabetize list items (#24103) (#24146)
* move list to component

* use helper instead

* add changelog

* clarify changelog copy

* delete components now that helper is in use

* move helper to util, remove template helper invokation

* add optional sorting to lazyPaginatedQuery based on sortBy query attribute

* Add serialization to entity-alias and entity so that they can be sorted by name on list view

* Same logic as base normalizeItems for extractLazyPaginatedData so that metadata shows on list

* Add headers

---------

Co-authored-by: claire bontempo <68122737+hellobontempo@users.noreply.github.com>
2023-11-15 20:58:10 +00:00

15 lines
461 B
JavaScript

export default function sortObjects(array, key) {
if (Array.isArray(array) && array?.every((e) => e[key] && typeof e[key] === 'string')) {
return array.sort((a, b) => {
// ignore upper vs lowercase
const valueA = a[key].toUpperCase();
const valueB = b[key].toUpperCase();
if (valueA < valueB) return -1;
if (valueA > valueB) return 1;
return 0;
});
}
// if not sortable, return original array
return array;
}