core/app/components/data-table/DataTablePagination.vue

65 lines
2.4 KiB
Vue

<script setup lang="ts">
import type { Table } from '@tanstack/vue-table';
import { ChevronLeft, ChevronRight, ChevronsLeft, ChevronsRight } from '@lucide/vue';
import { Button } from '@/components/ui/button';
import {
Select,
SelectContent,
SelectItem,
SelectTrigger,
SelectValue,
} from '@/components/ui/select';
const props = defineProps<{
table: Table<any>
}>()
</script>
<template>
<div class="flex items-center justify-between px-2 py-4">
<div />
<div class="flex items-center gap-6 lg:gap-8">
<div class="flex items-center gap-2">
<p class="text-sm font-medium">
Baris per halaman
</p>
<Select :model-value="`${table.getState().pagination.pageSize}`" @update:model-value="table.setPageSize">
<SelectTrigger class="h-8 w-17.5">
<SelectValue :placeholder="`${table.getState().pagination.pageSize}`" />
</SelectTrigger>
<SelectContent side="top">
<SelectItem v-for="pageSize in [10, 20, 30, 40, 50]" :key="pageSize" :value="`${pageSize}`">
{{ pageSize }}
</SelectItem>
</SelectContent>
</Select>
</div>
<div class="flex items-center justify-center text-sm font-medium">
Halaman {{ table.getState().pagination.pageIndex + 1 }} dari
{{ table.getPageCount() }}
</div>
<div class="flex items-center gap-2">
<Button variant="outline" class="hidden h-8 w-8 p-0 lg:flex" :disabled="!table.getCanPreviousPage()"
@click="table.setPageIndex(0)">
<span class="sr-only">Halaman pertama</span>
<ChevronsLeft class="h-4 w-4" />
</Button>
<Button variant="outline" class="h-8 w-8 p-0" :disabled="!table.getCanPreviousPage()"
@click="table.previousPage()">
<span class="sr-only">Halaman sebelumnya</span>
<ChevronLeft class="h-4 w-4" />
</Button>
<Button variant="outline" class="h-8 w-8 p-0" :disabled="!table.getCanNextPage()" @click="table.nextPage()">
<span class="sr-only">Halaman berikutnya</span>
<ChevronRight class="h-4 w-4" />
</Button>
<Button variant="outline" class="hidden h-8 w-8 p-0 lg:flex" :disabled="!table.getCanNextPage()"
@click="table.setPageIndex(table.getPageCount() - 1)">
<span class="sr-only">Halaman terakhir</span>
<ChevronsRight class="h-4 w-4" />
</Button>
</div>
</div>
</div>
</template>