refactor: Migrate Pagination to composition API (no-changelog) (#9752)

This commit is contained in:
Tomi Turtiainen
2024-06-17 13:43:06 +03:00
committed by GitHub
parent 403947a6a4
commit 7c70b782a1
5 changed files with 25 additions and 29 deletions

View File

@@ -74,7 +74,7 @@ interface DatatableProps {
rows: DatatableRow[];
currentPage?: number;
pagination?: boolean;
rowsPerPage?: number | '*';
rowsPerPage?: number;
}
defineOptions({ name: 'N8nDatatable' });
@@ -92,10 +92,6 @@ const rowsPerPageOptions = ref([10, 25, 50, 100]);
const $style = useCssModule();
const totalPages = computed(() => {
if (props.rowsPerPage === '*') {
return 1;
}
return Math.ceil(props.rows.length / props.rowsPerPage);
});
@@ -104,10 +100,6 @@ const totalRows = computed(() => {
});
const visibleRows = computed(() => {
if (props.rowsPerPage === '*') {
return props.rows;
}
const start = (props.currentPage - 1) * props.rowsPerPage;
const end = start + props.rowsPerPage;
@@ -123,10 +115,10 @@ function onUpdateCurrentPage(value: number) {
$emit('update:currentPage', value);
}
function onRowsPerPageChange(value: number | '*') {
function onRowsPerPageChange(value: number) {
$emit('update:rowsPerPage', value);
const maxPage = value === '*' ? 1 : Math.ceil(totalRows.value / value);
const maxPage = Math.ceil(totalRows.value / value);
if (maxPage < props.currentPage) {
onUpdateCurrentPage(maxPage);
}