This commit is contained in:
2024-05-19 11:58:36 +02:00
parent fb9a2f11fe
commit 27f146b945
5 changed files with 37 additions and 26 deletions
+5 -2
View File
@@ -1,10 +1,12 @@
import { MaybeRefOrGetter, computed, ref, toValue } from "vue";
import { Component, DefineComponent, MaybeRefOrGetter, computed, ref, toValue } from "vue";
export type HeaderComponent = Component | DefineComponent | string;
export type SortDirection = "asc" | "desc";
export type UseSortOptions = {
defaultSortKey?: string;
defaultSortDirection?: SortDirection;
ignoredColums?: MaybeRefOrGetter<string[]>;
headerComponent?: HeaderComponent;
};
export const useSort = <T>(array: MaybeRefOrGetter<T[]>, options?: UseSortOptions) => {
@@ -19,7 +21,8 @@ export const useSort = <T>(array: MaybeRefOrGetter<T[]>, options?: UseSortOption
onSort: sortBy,
showColumn,
currentSortKey: sortKey.value,
sortDirection: sortDirection.value
sortDirection: sortDirection.value,
headerComponent: options?.headerComponent,
}));
const sortedArray = computed(() => toValue(array).sort((a, b) => {