|
12 | 12 | striped |
13 | 13 | :items="items" |
14 | 14 | :fields="fields" |
15 | | - :items-per-page="perPage" |
16 | | - @row-clicked="rowClicked" |
17 | | - :pagination="$options.paginationProps" |
18 | | - index-column |
| 15 | + :items-per-page="5" |
19 | 16 | clickable-rows |
| 17 | + :active-page="activePage" |
| 18 | + @row-clicked="rowClicked" |
20 | 19 | > |
21 | | - <template #username="data"> |
22 | | - <td> |
23 | | - <strong>{{data.item.username}}</strong> |
24 | | - </td> |
25 | | - </template> |
26 | | - |
27 | 20 | <template #status="data"> |
28 | 21 | <td> |
29 | 22 | <CBadge :color="getBadge(data.item.status)"> |
|
32 | 25 | </td> |
33 | 26 | </template> |
34 | 27 | </CDataTable> |
| 28 | + <CPagination |
| 29 | + align="center" |
| 30 | + :double-arrows="false" |
| 31 | + :active-page="activePage" |
| 32 | + :pages="5" |
| 33 | + @update:activePage="pageChange" |
| 34 | + /> |
35 | 35 | </CCardBody> |
36 | 36 | </CCard> |
37 | 37 | </transition> |
|
43 | 43 | import usersData from './UsersData' |
44 | 44 | export default { |
45 | 45 | name: 'Users', |
46 | | - data: () => { |
| 46 | + data () { |
47 | 47 | return { |
48 | 48 | items: usersData, |
49 | 49 | fields: [ |
50 | | - { key: 'username', label: 'Name' }, |
| 50 | + { key: 'username', label: 'Name', _classes: 'font-weight-bold' }, |
51 | 51 | { key: 'registered' }, |
52 | 52 | { key: 'role' }, |
53 | 53 | { key: 'status' } |
54 | 54 | ], |
55 | | - perPage: 5, |
| 55 | + activePage: 1 |
56 | 56 | } |
57 | 57 | }, |
58 | | - paginationProps: { |
59 | | - align: 'center', |
60 | | - doubleArrows: false, |
61 | | - previousButtonHtml: 'prev', |
62 | | - nextButtonHtml: 'next' |
| 58 | + watch: { |
| 59 | + $route: { |
| 60 | + immediate: true, |
| 61 | + handler (route) { |
| 62 | + if (route.query && route.query.page) { |
| 63 | + this.activePage = Number(route.query.page) |
| 64 | + } |
| 65 | + } |
| 66 | + } |
63 | 67 | }, |
64 | 68 | methods: { |
65 | 69 | getBadge (status) { |
66 | | - return status === 'Active' ? 'success' |
67 | | - : status === 'Inactive' ? 'secondary' |
68 | | - : status === 'Pending' ? 'warning' |
69 | | - : status === 'Banned' ? 'danger' : 'primary' |
70 | | - }, |
71 | | - userLink (id) { |
72 | | - return `users/${id.toString()}` |
| 70 | + switch (status) { |
| 71 | + case 'Active': return 'success' |
| 72 | + case 'Inactive': return 'secondary' |
| 73 | + case 'Pending': return 'warning' |
| 74 | + case 'Banned': return 'danger' |
| 75 | + default: 'primary' |
| 76 | + } |
73 | 77 | }, |
74 | 78 | rowClicked (item, index) { |
75 | | - const userLink = this.userLink(index + 1) |
76 | | - this.$router.push({path: userLink}) |
| 79 | + this.$router.push({path: `users/${index + 1}`}) |
| 80 | + }, |
| 81 | + pageChange (val) { |
| 82 | + this.$router.push({ query: { page: val }}) |
77 | 83 | } |
78 | 84 | } |
79 | 85 | } |
|
0 commit comments