Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed on-reload page listing issues #2

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions src/components/vue-pagination-tw.vue
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ const emit = defineEmits<{

const pageInput = ref<number>(1)

const totalPages = Math.ceil(props.totalItems / props.perPage)
const totalPages = computed(() => Math.ceil(props.totalItems / props.perPage))

const paginationFrom = computed(() => (props.currentPage - 1) * props.perPage + 1)

Expand All @@ -64,12 +64,12 @@ const isFirstPage = computed(() => {
})

const isLastPage = computed(() => {
return props.currentPage >= totalPages
return props.currentPage >= totalPages.value
})

// methods
const changePage = (page: number) => {
if (page > 0 && page <= totalPages) {
if (page > 0 && page <= totalPages.value) {
emit('page-changed', page)
}
}
Expand All @@ -82,15 +82,15 @@ const rangeStart = computed(() => {

const rangeEnd = computed(() => {
var end = (props.currentPage + props.pageRange)
return (end < totalPages) ? end : totalPages
return (end < totalPages.value) ? end : totalPages.value
})

const hasFirst = () => {
return rangeStart.value !== 1
}

const hasLast = () => {
return rangeEnd.value < totalPages
return rangeEnd.value < totalPages.value
}

const calculatedPages = computed(() => {
Expand Down Expand Up @@ -162,8 +162,8 @@ const calculatedPages = computed(() => {
aria-current="page"
class="bg-white border border-gray-300 text-gray-500 relative inline-flex items-center px-4 py-2 text-sm font-medium"
v-if="hasLast()"
@click.prevent="changePage(totalPages)"
>{{ totalPages }}</a>
@click.prevent="changePage(totalPages.value)"
>{{ totalPages.value }}</a>
Comment on lines +165 to +166
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
@click.prevent="changePage(totalPages.value)"
>{{ totalPages.value }}</a>
@click.prevent="changePage(totalPages)"
>{{ totalPages }}</a>

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nicely work!

I've tried to build this PR and found the error that .value was in the template syntax. I removed them then everything worked as expected.

<a
href="#"
class="relative inline-flex items-center px-2 py-2 rounded-r-md border border-gray-300 bg-white text-sm font-medium text-gray-500 hover:bg-gray-50"
Expand Down