Add pagination to lists

This commit is contained in:
Kailash Nadh 2020-08-22 19:58:21 +05:30
parent 1ef1c5a61c
commit 8fe601aa4a
2 changed files with 21 additions and 8 deletions

View File

@ -91,8 +91,8 @@ export const getDashboardCharts = () => http.get('/api/dashboard/charts',
{ loading: models.dashboard }); { loading: models.dashboard });
// Lists. // Lists.
export const getLists = () => http.get('/api/lists', export const getLists = (params) => http.get('/api/lists',
{ loading: models.lists, store: models.lists }); { params, loading: models.lists, store: models.lists });
export const createList = (data) => http.post('/api/lists', data, export const createList = (data) => http.post('/api/lists', data,
{ loading: models.lists }); { loading: models.lists });

View File

@ -14,10 +14,13 @@
<b-table <b-table
:data="lists.results" :data="lists.results"
:loading="loading.lists" :loading="loading.lists"
hoverable hoverable default-sort="createdAt"
default-sort="createdAt"> paginated backend-pagination pagination-position="both" @page-change="onPageChange"
:current-page="queryParams.page" :per-page="lists.perPage" :total="lists.total"
>
<template slot-scope="props"> <template slot-scope="props">
<b-table-column field="name" label="Name" sortable width="25%"> <b-table-column field="name" label="Name" sortable width="25%"
paginated backend-pagination pagination-position="both" @page-change="onPageChange">
<div> <div>
<router-link :to="{name: 'subscribers_list', params: { listID: props.row.id }}"> <router-link :to="{name: 'subscribers_list', params: { listID: props.row.id }}">
{{ props.row.name }} {{ props.row.name }}
@ -112,10 +115,16 @@ export default Vue.extend({
curItem: null, curItem: null,
isEditing: false, isEditing: false,
isFormVisible: false, isFormVisible: false,
queryParams: { page: 1 },
}; };
}, },
methods: { methods: {
onPageChange(p) {
this.queryParams.page = p;
this.getLists();
},
// Show the edit list form. // Show the edit list form.
showEditForm(list) { showEditForm(list) {
this.curItem = list; this.curItem = list;
@ -131,7 +140,11 @@ export default Vue.extend({
}, },
formFinished() { formFinished() {
this.$api.getLists(); this.getLists();
},
getLists() {
this.$api.getLists({ page: this.queryParams.page });
}, },
deleteList(list) { deleteList(list) {
@ -139,7 +152,7 @@ export default Vue.extend({
'Are you sure? This does not delete subscribers.', 'Are you sure? This does not delete subscribers.',
() => { () => {
this.$api.deleteList(list.id).then(() => { this.$api.deleteList(list.id).then(() => {
this.$api.getLists(); this.getLists();
this.$buefy.toast.open({ this.$buefy.toast.open({
message: `'${list.name}' deleted`, message: `'${list.name}' deleted`,
@ -174,7 +187,7 @@ export default Vue.extend({
}, },
mounted() { mounted() {
this.$api.getLists(); this.getLists();
}, },
}); });
</script> </script>