Skip to content

Instantly share code, notes, and snippets.

@laurisstepanovs
Created August 23, 2023 19:24
Show Gist options
  • Save laurisstepanovs/351805053da6970f474be4cd88ac0af1 to your computer and use it in GitHub Desktop.
Save laurisstepanovs/351805053da6970f474be4cd88ac0af1 to your computer and use it in GitHub Desktop.
startPage.ts
const startPage = computed(() => {
const floorVal = Math.floor(props.maxVisibleButtons / 2);
if (
props.totalPages < props.maxVisibleButtons ||
props.currentPage === 1 ||
props.currentPage <= Math.floor(props.maxVisibleButtons / 2) ||
(props.currentPage + floorVal > props.totalPages &&
props.totalPages === props.maxVisibleButtons)
) {
return 1;
}
if (props.currentPage + floorVal > props.totalPages) {
return props.totalPages - props.maxVisibleButtons + 1;
}
return props.currentPage - floorVal;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment