DemoDataTableExternalPagination.vue
2.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
<script setup lang="ts">
import data from '@/views/demos/forms/tables/data-table/datatable'
import type { Data } from '@db/pages/datatable/types'
const userList = ref<Data[]>([])
const options = ref({ page: 1, itemsPerPage: 5, sortBy: [''], sortDesc: [false] })
// headers
const headers = [
{ title: 'NAME', key: 'fullName' },
{ title: 'EMAIL', key: 'email' },
{ title: 'DATE', key: 'startDate' },
{ title: 'SALARY', key: 'salary' },
{ title: 'AGE', key: 'age' },
{ title: 'STATUS', key: 'status' },
]
const resolveStatusVariant = (status: number) => {
if (status === 1)
return { color: 'primary', text: 'Current' }
else if (status === 2)
return { color: 'success', text: 'Professional' }
else if (status === 3)
return { color: 'error', text: 'Rejected' }
else if (status === 4)
return { color: 'warning', text: 'Resigned' }
else
return { color: 'info', text: 'Applied' }
}
onMounted(() => {
userList.value = JSON.parse(JSON.stringify(data))
})
</script>
<template>
<VDataTable
:headers="headers"
:items="userList"
:items-per-page="options.itemsPerPage"
:page="options.page"
:options="options"
class="text-no-wrap"
>
<!-- full name -->
<template #item.fullName="{ item }">
<div class="d-flex align-center">
<VAvatar
size="32"
:color="item.avatar ? '' : 'primary'"
:class="item.avatar ? '' : 'v-avatar-light-bg primary--text'"
:variant="!item.avatar ? 'tonal' : undefined"
>
<VImg
v-if="item.avatar"
:src="item.avatar"
/>
<span
v-else
class="text-sm"
>{{ avatarText(item.fullName) }}</span>
</VAvatar>
<div class="d-flex flex-column ms-3">
<span class="d-block font-weight-medium text-high-emphasis text-truncate">{{ item.fullName }}</span>
<small>{{ item.post }}</small>
</div>
</div>
</template>
<!-- status -->
<template #item.status="{ item }">
<VChip
:color="resolveStatusVariant(item.status).color"
class="font-weight-medium"
size="small"
>
{{ resolveStatusVariant(item.status).text }}
</VChip>
</template>
<template #bottom>
<VCardText class="pt-2">
<div class="d-flex flex-wrap justify-center justify-sm-space-between gap-y-2 mt-2">
<VSelect
v-model="options.itemsPerPage"
:items="[5, 10, 25, 50, 100]"
label="Rows per page:"
variant="underlined"
style="max-inline-size: 8rem;min-inline-size: 5rem;"
/>
<VPagination
v-model="options.page"
:total-visible="$vuetify.display.smAndDown ? 2 : 3"
:length="Math.ceil(userList.length / options.itemsPerPage)"
/>
</div>
</VCardText>
</template>
</VDataTable>
</template>