Skip to content

Instantly share code, notes, and snippets.

@AbdullahiAbdulkabir
Created December 24, 2021 11:31
Show Gist options
  • Save AbdullahiAbdulkabir/3d4e4029584b10d1d02f3e91ef8314a3 to your computer and use it in GitHub Desktop.
Save AbdullahiAbdulkabir/3d4e4029584b10d1d02f3e91ef8314a3 to your computer and use it in GitHub Desktop.
Simple pagination with Laravel format
1. Import or use component above like this `<SimplePagination :pagination="paginationData" :callback="getApplications" />`
2. paginationData is the whole data coming from the laravel endpoint with has the pagination and data in it
3. getApplications is the method that fetch the applications on first load and keeps fetching the values.
<template>
<div style="display:inline-block">
<ul class="pagination pagination-danger" v-if="pagination">
<li
class="page-item"
:class="[pagination.prev_page_url != null ? active : 'disabled']"
>
<a href="javascript:void(0);" class="page-link" @click="fetchPrevious">prev</a>
</li>
<li
class="page-item"
:class="[pagination.next_page_url != null ? active : 'disabled']"
>
<a href="javascript:void(0);" class="page-link" @click="fetchNext">next</a>
</li>
</ul>
</div>
</template>
<script>
export default {
name: "SimplePagination",
data() {
return {};
},
props: ["pagination", "callback"],
methods: {
fetchNext() {
if (this.pagination.next_page_url != null) {
let url = new URL(this.pagination.next_page_url);
let params = new URLSearchParams(url.search);
this.callback(params.get("page"));
}
},
fetchPrevious() {
if (this.pagination.prev_page_url != null) {
let url = new URL(this.pagination.prev_page_url);
let params = new URLSearchParams(url.search);
this.callback(params.get("page"));
}
}
},
created() {}
};
</script>
<style scoped>
.page-item.active .page-link {
z-index: 0;
}
</style>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment