Skip to content

Commit

Permalink
feat: add pagination in user table
Browse files Browse the repository at this point in the history
  • Loading branch information
newarifrh committed Jun 28, 2024
1 parent 524c179 commit 80e500e
Showing 1 changed file with 28 additions and 5 deletions.
33 changes: 28 additions & 5 deletions src/views/user/ListUserView.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<template>
<div>

<div style="height: 100%; display: flex; flex-direction: column">
<div style="display: flex; justify-content: space-between;">
<div style="display: flex; align-items: center"></div>
<div style="display: flex; align-items: center; gap:10px">
Expand All @@ -13,11 +12,12 @@
</div>

<el-divider />
<el-table ref="usersTableRef" v-loading="loading" :data="filterUsers" row-key="_id" style="width: 100%">
<el-table ref="usersTableRef" v-loading="loading" :data="paginatedData" row-key="_id"
style="width: 100%; flex: 1; margin-bottom: 20px;">
<el-table-column type="index" label="No" />
<el-table-column label="Nama" sortable prop="name" />
<el-table-column label="NIP" prop="nip" />
<el-table-column label="Tim" prop="team" />
<el-table-column label="Tim" prop="team" :formatter="teamFormatter" />
<el-table-column label="Posisi" prop="position" />

<el-table-column align="right">
Expand All @@ -26,7 +26,11 @@
</template>
</el-table-column>
</el-table>
<div style="margin-top: 20px"></div>
<div style="display: flex; gap: 20px;">
<el-pagination background layout="total, sizes, prev, pager, next, jumper" :total="total"
:page-sizes="[10, 25, 50, 100]" v-model:page-size="pageSize" :current-page="currentPage"
@current-change="handlePageChange" class="pagination" />
</div>
</div>
</template>

Expand All @@ -51,6 +55,25 @@ const headers = ref({
Authorization: `Bearer ${auth.token}`,
});
const uploadUrl = ref(`${BASE_URL}/v1/users/upload`);
const pageSize = ref(10)
const currentPage = ref(1);
const total = computed(() => filterUsers.value.length);
const paginatedData = computed(() => {
const start = (currentPage.value - 1) * pageSize.value;
const end = start + pageSize.value;
return filterUsers.value.slice(start, end);
});
const handlePageChange = (page: number) => {
currentPage.value = page;
};
const teamFormatter = (row: any) => {
if (row.team == null) return "-";
return row.team;
};
const handleError = (
error: Error,
Expand Down

0 comments on commit 80e500e

Please sign in to comment.