Skip to content

Commit a748213

Browse files
committed
Improved: Table sorting now available. rustfs/rustfs#1147
1 parent 3479ae7 commit a748213

File tree

4 files changed

+45
-7
lines changed

4 files changed

+45
-7
lines changed

components/data-table/data-table.vue

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { cn } from '@/lib/utils'
77
import type { Column, Table } from '@tanstack/vue-table'
88
import { FlexRender } from '@tanstack/vue-table'
99
import { computed } from 'vue'
10+
import { Icon } from '#components'
1011
1112
const props = withDefaults(
1213
defineProps<{
@@ -51,6 +52,26 @@ const getColumnStyles = (column: Column<TData, unknown>) => {
5152
5253
return Object.keys(styles).length > 0 ? styles : undefined
5354
}
55+
56+
const canSort = (column: Column<TData, unknown>) => {
57+
const def = column.columnDef as any
58+
// 如果 enableSorting 明确设置为 false,则不显示排序
59+
if (def.enableSorting === false) {
60+
return false
61+
}
62+
63+
// 直接检查列定义对象中是否真的存在 accessorKey 或 accessorFn
64+
// 使用 Object.prototype.hasOwnProperty.call 来确保属性直接存在于对象上
65+
const hasAccessorKey =
66+
Object.prototype.hasOwnProperty.call(def, 'accessorKey') &&
67+
typeof def.accessorKey === 'string' &&
68+
def.accessorKey.length > 0
69+
70+
const hasAccessorFn = Object.prototype.hasOwnProperty.call(def, 'accessorFn') && typeof def.accessorFn === 'function'
71+
72+
// 只有明确配置了 accessorKey 或 accessorFn 时才显示排序
73+
return hasAccessorKey || hasAccessorFn
74+
}
5475
</script>
5576

5677
<template>
@@ -73,11 +94,19 @@ const getColumnStyles = (column: Column<TData, unknown>) => {
7394
:class="bodyHeight ? undefined : 'py-2'"
7495
:style="getColumnStyles(header.column)"
7596
>
76-
<FlexRender
77-
v-if="!header.isPlaceholder"
78-
:render="header.column.columnDef.header"
79-
:props="header.getContext()"
80-
/>
97+
<template v-if="!header.isPlaceholder">
98+
<div
99+
v-if="canSort(header.column)"
100+
class="flex items-center gap-2 cursor-pointer select-none hover:text-foreground"
101+
@click="header.column.getToggleSortingHandler()?.($event)"
102+
>
103+
<FlexRender :render="header.column.columnDef.header" :props="header.getContext()" />
104+
<Icon v-if="header.column.getIsSorted() === 'asc'" name="ri:arrow-up-s-line" class="size-4" />
105+
<Icon v-else-if="header.column.getIsSorted() === 'desc'" name="ri:arrow-down-s-line" class="size-4" />
106+
<Icon v-else name="ri:arrow-up-down-line" class="size-4 text-muted-foreground opacity-50" />
107+
</div>
108+
<FlexRender v-else :render="header.column.columnDef.header" :props="header.getContext()" />
109+
</template>
81110
</TableHead>
82111
</TableRow>
83112
</TableHeader>

components/object/list.vue

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,10 @@ const columns = computed<ColumnDef<ObjectRow, any>[]>(() => {
271271
{
272272
id: 'object',
273273
header: () => t('Object'),
274+
accessorFn: row => {
275+
const key = row.Key ?? ''
276+
return prefix.value ? key.substring(prefix.value.length) : key
277+
},
274278
cell: ({ row }: any) => {
275279
const key = row.original.Key ?? ''
276280
const displayKey = prefix.value ? key.substring(prefix.value.length) : key
@@ -302,11 +306,16 @@ const columns = computed<ColumnDef<ObjectRow, any>[]>(() => {
302306
{
303307
id: 'size',
304308
header: () => t('Size'),
309+
accessorFn: row => (row.type === 'object' ? row.Size : -1),
305310
cell: ({ row }: any) => (row.original.type === 'object' ? formatBytes(row.original.Size) : '-'),
306311
},
307312
{
308313
id: 'lastModified',
309314
header: () => t('Last Modified'),
315+
accessorFn: row => {
316+
if (row.type === 'prefix' || !row.LastModified) return ''
317+
return new Date(row.LastModified).getTime()
318+
},
310319
cell: ({ row }: any) =>
311320
row.original.LastModified ? dayjs(row.original.LastModified).format('YYYY-MM-DD HH:mm:ss') : '-',
312321
},

pages/access-keys/index.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ const columns: ColumnDef<RowData>[] = [
114114
cell: ({ row }) => h('span', row.original.name || '-'),
115115
},
116116
{
117-
accessorKey: 'description',
117+
id: 'description',
118118
header: () => t('Description'),
119119
cell: ({ row }) => h('span', row.original.description || '-'),
120120
},

pages/replication/index.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ const columns: ColumnDef<ReplicationRule>[] = [
8989
cell: ({ row }) => h('span', String(row.original.Priority ?? '-')),
9090
},
9191
{
92-
accessorKey: 'Filter',
92+
id: 'Filter',
9393
header: () => t('Prefix'),
9494
cell: ({ row }) => h('span', row.original.Filter?.Prefix || '-'),
9595
},

0 commit comments

Comments
 (0)