Skip to content

feat: add go first and go last on VPagination #17

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
3 changes: 1 addition & 2 deletions src/components/data-table/VTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
:model-value="page"
@update:model-value="updatePage"
:total="items.length"
:itemsPerPage="itemsPerPage"
/>
</template>

Expand Down Expand Up @@ -65,9 +66,7 @@ export default {

return {
updatePage,

paginatedItems,

columns
};
}
Expand Down
49 changes: 40 additions & 9 deletions src/components/pagination/VPagination.vue
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
<template>
<div class="input-group">
<button
class="btn text-secondary-dark align-items-center d-flex"
@click="goFirst"
>
go first
</button>
<button
class="btn btn-outline-primary"
@click="goPrev"
>{{ $t('Previous') }}</button>
>{{ $t('Previous') }}
</button>

<input
:value="modelValue"
Expand All @@ -15,7 +22,14 @@
<button
class="btn btn-outline-primary"
@click="goNext"
>{{ $t('Next') }}</button>
>{{ $t('Next') }}
</button>
<button
class="btn text-primary align-items-center d-flex"
@click="goLast"
>
go last
</button>
</div>
</template>

Expand All @@ -31,21 +45,28 @@ export default {
total: {
type: Number,
required: true
},
itemsPerPage: {
type: Number,
required: true
}
},

emits: ['update:modelValue'],

setup(props, context) {
function updateValue(value) {
if (value < 1) {
value = 1;
}
if (value > Math.floor(props.total / props.itemsPerPage)) {
value = Math.ceil(props.total / props.itemsPerPage)
} else {
if (value < 1) {
value = 1;
}

if (value > props.total) {
value = props.total;
if (value > props.total) {
value = props.total;
}
}

context.emit('update:modelValue', value);
}

Expand All @@ -57,10 +78,20 @@ export default {
updateValue(props.modelValue - 1);
}

function goFirst() {
updateValue(props.modelValue - props.modelValue + 1);
}

function goLast() {
updateValue(Math.ceil(props.total / props.itemsPerPage));
}

return {
updateValue,
goPrev,
goNext
goNext,
goFirst,
goLast
};
}
}
Expand Down