mirror of
https://github.com/nuxt/ui.git
synced 2026-09-14 19:51:10 +08:00
95e1626a01
Resolves #5817
87 lines
1.6 KiB
Vue
87 lines
1.6 KiB
Vue
<script setup lang="ts">
|
|
import type { TableColumn } from '@nuxt/ui'
|
|
import { useSortable } from '@vueuse/integrations/useSortable'
|
|
|
|
type Payment = {
|
|
id: string
|
|
date: string
|
|
email: string
|
|
amount: number
|
|
}
|
|
|
|
const data = ref<Payment[]>([{
|
|
id: '4600',
|
|
date: '2024-03-11T15:30:00',
|
|
email: 'james.anderson@example.com',
|
|
amount: 594
|
|
}, {
|
|
id: '4599',
|
|
date: '2024-03-11T10:10:00',
|
|
email: 'mia.white@example.com',
|
|
amount: 276
|
|
}, {
|
|
id: '4598',
|
|
date: '2024-03-11T08:50:00',
|
|
email: 'william.brown@example.com',
|
|
amount: 315
|
|
}, {
|
|
id: '4597',
|
|
date: '2024-03-10T19:45:00',
|
|
email: 'emma.davis@example.com',
|
|
amount: 529
|
|
}])
|
|
|
|
const columns: TableColumn<Payment>[] = [{
|
|
accessorKey: 'id',
|
|
header: '#',
|
|
cell: ({ row }) => `#${row.getValue('id')}`
|
|
}, {
|
|
accessorKey: 'date',
|
|
header: 'Date',
|
|
cell: ({ row }) => {
|
|
return new Date(row.getValue('date')).toLocaleString('en-US', {
|
|
day: 'numeric',
|
|
month: 'short',
|
|
hour: '2-digit',
|
|
minute: '2-digit',
|
|
hour12: false
|
|
})
|
|
}
|
|
}, {
|
|
accessorKey: 'email',
|
|
header: 'Email'
|
|
}, {
|
|
accessorKey: 'amount',
|
|
header: 'Amount',
|
|
meta: {
|
|
class: {
|
|
th: 'text-right',
|
|
td: 'text-right font-medium'
|
|
}
|
|
},
|
|
cell: ({ row }) => {
|
|
const amount = Number.parseFloat(row.getValue('amount'))
|
|
return new Intl.NumberFormat('en-US', {
|
|
style: 'currency',
|
|
currency: 'EUR'
|
|
}).format(amount)
|
|
}
|
|
}]
|
|
|
|
useSortable('.my-table-tbody', data, {
|
|
animation: 150
|
|
})
|
|
</script>
|
|
|
|
<template>
|
|
<UTable
|
|
ref="table"
|
|
:data="data"
|
|
:columns="columns"
|
|
:ui="{
|
|
tbody: 'my-table-tbody'
|
|
}"
|
|
class="flex-1"
|
|
/>
|
|
</template>
|