Add itemsPerPage selector to pagination

This commit is contained in:
Daniel_I_Am 2021-09-02 15:24:06 +02:00
parent c3526af06c
commit f5c839f1f9
3 changed files with 24 additions and 6 deletions

View File

@ -114,8 +114,12 @@ export default {
}, },
}, },
watch: { watch: {
itemsPerPage() { itemsPerPage(value) {
this.page = 0; if (this.page > 0) {
this.page = 0;
} else {
this.updateList(value, this.page);
}
}, },
page(value) { page(value) {
this.updateList(this.itemsPerPage, value); this.updateList(this.itemsPerPage, value);

View File

@ -6,6 +6,12 @@
<button @click="gotoPage(page + 1)">Next</button> <button @click="gotoPage(page + 1)">Next</button>
<button @click="gotoPage(maxPages)">Last</button> <button @click="gotoPage(maxPages)">Last</button>
</div> </div>
<div class="pagination">
<button class="unselectable">Items per page</button>
<button :class="{ active: (itemsPerPage === n) }" @click="setPageSize(n)" v-for="n of [5, 10, 20, 50]" :key="n">{{ n }}</button>
</div>
</template> </template>
<script> <script>
@ -29,6 +35,9 @@ export default {
this.$emit('update:page', page); this.$emit('update:page', page);
} }
}, },
setPageSize(n) {
this.$emit('update:itemsPerPage', n);
}
} }
} }
</script> </script>

View File

@ -2,10 +2,14 @@
display: flex; display: flex;
justify-content: flex-start; justify-content: flex-start;
&:not(:last-of-type) {
margin-bottom: .5rem;
}
button { button {
background-color: #1c2d35; background-color: $background;
border: 1px solid white; border: 1px solid white;
color: white; color: $text-color;
height: 40px; height: 40px;
width: 120px; width: 120px;
@ -17,8 +21,9 @@
cursor: pointer; cursor: pointer;
} }
button:not(.unselectable):hover { button:not(.unselectable):hover,
background-color: #2d3e46; button.active {
background-color: $background-lighter;
} }
button:not(:last-child) { button:not(:last-child) {