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

Implemented: Dxp pagination component(#322) #356

Merged
merged 8 commits into from
Jan 17, 2025
90 changes: 90 additions & 0 deletions src/components/DxpPagination.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
<template>
<ion-button size="small" fill="clear" color="medium" @click="goToFirstPage" :disabled="currentPage === 1">
<ion-icon slot="icon-only" :icon="playSkipBackOutline" />
</ion-button>
<ion-button size="small" fill="clear" color="medium" @click="goToPreviousPage" :disabled="currentPage === 1">
<ion-icon slot="icon-only" :icon="chevronBackOutline" />
</ion-button>

<ion-button
v-for="pageCount in getDisplayedPageCounts()"
:key="pageCount" size="small" fill="clear"
ymaheshwari1 marked this conversation as resolved.
Show resolved Hide resolved
:color="currentPage === pageCount ? 'dark' : 'medium'"
:class="{ 'selected-page': currentPage === pageCount }"
@click="updateCurrentPage(pageCount)"
>
{{ pageCount }}
</ion-button>

<ion-button size="small" fill="clear" color="medium" @click="goToNextPage" :disabled="currentPage === totalPages">
<ion-icon slot="icon-only" :icon="chevronForwardOutline" />
</ion-button>
<ion-button size="small" fill="clear" color="medium" @click="goToLastPage" :disabled="currentPage === totalPages">
<ion-icon slot="icon-only" :icon="playSkipForwardOutline" />
</ion-button>
</template>

<script setup lang="ts">
import { ref, computed, defineProps, defineEmits } from 'vue';
import { IonButton, IonIcon } from '@ionic/vue';
import { playSkipBackOutline, chevronBackOutline, chevronForwardOutline, playSkipForwardOutline } from 'ionicons/icons';

const props = defineProps({
itemsPerPage: {
type: Number,
required: true
},
totalItems: {
type: Number,
required: true
}
});
const emit = defineEmits(['updatePageCount']);

const totalPages = computed(() => Math.ceil(props.totalItems / props.itemsPerPage))
const currentPage = ref(1);

// Function to determine which page numbers to display based on the current page
function getDisplayedPageCounts() {
const pages = [];
const startPage = Math.max(1, currentPage.value - 1);
const endPage = Math.min(totalPages.value, startPage + 2);

for(let i = startPage; i <= endPage; i++) {
pages.push(i);
}
return pages;
}

// Changes the current page to the specified page and emits an event to notify the parent component to fetch new items.
function updateCurrentPage(pageCount: number) {
if(pageCount < 1 || pageCount > totalPages.value) {
return;
}
currentPage.value = pageCount;
const viewIndex = (currentPage.value - 1);
ymaheshwari1 marked this conversation as resolved.
Show resolved Hide resolved
emit('updatePageCount', viewIndex);
}

function goToFirstPage() {
updateCurrentPage(1);
}

function goToPreviousPage() {
updateCurrentPage(currentPage.value - 1);
}

function goToNextPage() {
updateCurrentPage(currentPage.value + 1);
}

function goToLastPage() {
updateCurrentPage(totalPages.value);
}
ymaheshwari1 marked this conversation as resolved.
Show resolved Hide resolved
</script>

<style scoped>
.selected-page {
font-size: 15px;
}
</style>
1 change: 1 addition & 0 deletions src/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export { default as DxpLanguageSwitcher } from './DxpLanguageSwitcher.vue';
export { default as DxpLogin } from './DxpLogin.vue';
export { default as DxpMenuFooterNavigation } from './DxpMenuFooterNavigation.vue';
export { default as DxpOmsInstanceNavigator } from './DxpOmsInstanceNavigator.vue'
export { default as DxpPagination } from './DxpPagination.vue'
export { default as DxpProductIdentifier } from "./DxpProductIdentifier.vue";
export { default as DxpProductStoreSelector } from "./DxpProductStoreSelector.vue"
export { default as DxpShopifyImg } from './DxpShopifyImg.vue';
Expand Down
4 changes: 3 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ declare var process: any;
import { createPinia } from "pinia";
import { useProductIdentificationStore } from "./store/productIdentification";
import { useAuthStore } from "./store/auth";
import { DxpAppVersionInfo, DxpFacilitySwitcher, DxpGitBookSearch, DxpImage, DxpLanguageSwitcher, DxpLogin, DxpMenuFooterNavigation, DxpOmsInstanceNavigator, DxpProductIdentifier, DxpProductStoreSelector, DxpShopifyImg, DxpTimeZoneSwitcher, DxpUserProfile } from "./components";
import { DxpAppVersionInfo, DxpFacilitySwitcher, DxpGitBookSearch, DxpImage, DxpLanguageSwitcher, DxpLogin, DxpMenuFooterNavigation, DxpOmsInstanceNavigator, DxpPagination, DxpProductIdentifier, DxpProductStoreSelector, DxpShopifyImg, DxpTimeZoneSwitcher, DxpUserProfile } from "./components";
import { goToOms, getProductIdentificationValue } from "./utils";
import { initialiseFirebaseApp } from "./utils/firebase"
import piniaPluginPersistedstate from 'pinia-plugin-persistedstate'
Expand Down Expand Up @@ -76,6 +76,7 @@ export let dxpComponents = {
app.component('DxpLogin', DxpLogin)
app.component('DxpMenuFooterNavigation', DxpMenuFooterNavigation)
app.component('DxpOmsInstanceNavigator', DxpOmsInstanceNavigator)
app.component('DxpPagination', DxpPagination)
app.component('DxpProductIdentifier', DxpProductIdentifier)
app.component('DxpProductStoreSelector', DxpProductStoreSelector)
app.component('DxpShopifyImg', DxpShopifyImg)
Expand Down Expand Up @@ -138,6 +139,7 @@ export {
DxpLogin,
DxpMenuFooterNavigation,
DxpOmsInstanceNavigator,
DxpPagination,
DxpProductIdentifier,
DxpShopifyImg,
DxpTimeZoneSwitcher,
Expand Down
Loading