diff --git a/apps/list/pages/content-creators.vue b/apps/list/pages/content-creators.vue index ca3a914..73938dd 100644 --- a/apps/list/pages/content-creators.vue +++ b/apps/list/pages/content-creators.vue @@ -3,7 +3,9 @@ import { FlexRender, getCoreRowModel, useVueTable, + type SortingState, createColumnHelper, + getSortedRowModel, } from "@tanstack/vue-table" useHead({ @@ -15,16 +17,27 @@ type ContentCreator = { name: string subscribers: number } -const _contentCreators: ContentCreator[] = [ +const contentCreators = ref([ { channelId: "asdf", name: "Channel A", subscribers: 9999, }, -] + { + channelId: "xyzw", + name: "Channel B", + subscribers: 1111, + }, +]) +function sortIcon(isSorted: false | "asc" | "desc") { + if (isSorted === "asc") return "fa6-solid:sort-up" + if (isSorted === "desc") return "fa6-solid:sort-down" + return "fa6-solid:sort" +} + +const sorting = ref([]) const columnHelper = createColumnHelper() -const contentCreators = ref(_contentCreators) const t = useVueTable({ get data() { return contentCreators.value @@ -38,7 +51,19 @@ const t = useVueTable({ header: "Subscribers", }), ], + state: { + get sorting() { + return sorting.value + }, + }, + onSortingChange: (updaterOrValue) => { + sorting.value = + typeof updaterOrValue === "function" + ? updaterOrValue(sorting.value) + : updaterOrValue + }, getCoreRowModel: getCoreRowModel(), + getSortedRowModel: getSortedRowModel(), }) @@ -55,16 +80,29 @@ const t = useVueTable({ :key="headerGroup.id" > - +
+ + +