Skip to content

Commit

Permalink
Merge pull request #356 from R-Sourabh/#322-dxp-pagination
Browse files Browse the repository at this point in the history
Implemented: Dxp pagination component(#322)
  • Loading branch information
ymaheshwari1 authored Jan 17, 2025
2 parents 35e4c21 + 8cb357d commit d2a96a6
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 1 deletion.
68 changes: 68 additions & 0 deletions src/components/DxpPagination.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<template>
<ion-button size="small" fill="clear" color="medium" @click="updateCurrentPage(1)" :disabled="currentPage === 1">
<ion-icon slot="icon-only" :icon="playSkipBackOutline" />
</ion-button>
<ion-button size="small" fill="clear" color="medium" @click="updateCurrentPage(currentPage - 1)" :disabled="currentPage === 1">
<ion-icon slot="icon-only" :icon="chevronBackOutline" />
</ion-button>

<ion-button
v-for="pageIndex in getDisplayedPageIndexes()"
:key="pageIndex"
fill="clear"
:size="currentPage === pageIndex ? 'default' : 'small'"
:color="currentPage === pageIndex ? 'dark' : 'medium'"
@click="updateCurrentPage(pageIndex)"
>
{{ pageIndex }}
</ion-button>

<ion-button size="small" fill="clear" color="medium" @click="updateCurrentPage(currentPage + 1)" :disabled="currentPage === totalPages">
<ion-icon slot="icon-only" :icon="chevronForwardOutline" />
</ion-button>
<ion-button size="small" fill="clear" color="medium" @click="updateCurrentPage(totalPages)" :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(['updatePageIndex']);
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 getDisplayedPageIndexes() {
const pages = [];
const startPage = Math.max(1, currentPage.value - 1);
const endPage = Math.min(totalPages.value, currentPage.value + 1);
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(pageIndex: number) {
currentPage.value = pageIndex;
// Subtracting 1 from the currentPage to calculate the viewIndex, as viewIndex starts from 0.
// This ensures that the first set of items is requested with viewIndex = 0 by default from the parent component.
// On subsequent page changes, the viewIndex emitted from here is adjusted accordingly to manage API calls efficiently.
const viewIndex = currentPage.value - 1;
emit('updatePageIndex', viewIndex);
}
</script>
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

0 comments on commit d2a96a6

Please sign in to comment.