Commit d1cdf9ed authored by esatakpunar's avatar esatakpunar

add pagination server side

parent 5a0feaa9
...@@ -14,29 +14,38 @@ export default { ...@@ -14,29 +14,38 @@ export default {
...mapGetters("customers", [ ...mapGetters("customers", [
"headers", "headers",
"customerList", "customerList",
"filteredCustomerList",
"dialog", "dialog",
"loading", "loading",
"dialogHeaders", "dialogHeaders",
"editedItem", "editedItem",
"editedIndex", "editedIndex",
"getOptions",
"totalCustomers",
]), ]),
indexofColumn() { indexofColumn() {
return this.dialogHeaders.findIndex( return this.dialogHeaders.findIndex(
(header) => this.column == header.value (header) => this.column == header.value
); );
}, },
options: {
get() {
return this.getOptions;
},
set(data) {
this.setOptions(data);
},
},
}, },
methods: { methods: {
...mapActions("customers", [ ...mapActions("customers", [
"fetchCustomerData", "fetchCustomerData",
"toggleSingleExpand",
"closeDialog", "closeDialog",
"deleteCustomer", "deleteCustomer",
"deleteMultiCustomer", "deleteMultiCustomer",
"saveCustomer", "saveCustomer",
"editCustomer", "editCustomer",
"filterCustomer", "setOptions",
]), ]),
}, },
created() { created() {
...@@ -55,6 +64,8 @@ export default { ...@@ -55,6 +64,8 @@ export default {
:headers="headers" :headers="headers"
:items="customerList" :items="customerList"
:loading="loading" :loading="loading"
:options.sync="options"
:server-items-length="Number(totalCustomers)"
show-select show-select
class="evation-1" class="evation-1"
> >
...@@ -62,7 +73,6 @@ export default { ...@@ -62,7 +73,6 @@ export default {
<v-toolbar flat> <v-toolbar flat>
<v-toolbar-title>Customers</v-toolbar-title> <v-toolbar-title>Customers</v-toolbar-title>
<v-divider class="mx-4" inset vertical></v-divider> <v-divider class="mx-4" inset vertical></v-divider>
<v-btn <v-btn
large large
icon icon
......
import axios from "axios"; import axios from "axios";
export default { export default {
fetchCustomerData({ dispatch, commit }, data = {}) { fetchCustomerData({ commit, getters }, data = {}) {
let query; let query;
if (data.filterColumn == "all") { if (data.filterColumn == "all") {
query = "q=" + data.searchInput; query = "q=" + data.searchInput;
} else if (data.filterColumn) { } else if (data.filterColumn) {
query = data.filterColumn + "_like=" + data.searchInput; query = data.filterColumn + "_like=" + data.searchInput;
} }
let pageLimit = `&_page=${getters.getOptions.page}&_limit=${getters.getOptions.itemsPerPage}`;
let sort = `&_sort=${getters.getOptions.sortBy}&_order=${getters.getOptions.sortDesc}`;
commit("setLoading", true); commit("setLoading", true);
axios axios
.get(`http://localhost:3000/customers?${query}`) .get(`http://localhost:3000/customers?${query}${pageLimit}${sort}`)
.then((response) => { .then((response) => {
commit("setTotalCustomers", response.headers["x-total-count"]);
commit("setCustomerList", response.data); commit("setCustomerList", response.data);
dispatch("filterCustomer", { searchInput: "" });
commit("setLoading", false); commit("setLoading", false);
}) })
.catch((e) => { .catch((e) => {
console.log(e); console.log(e);
}); });
}, },
setOptions({ commit, dispatch }, data) {
commit("setOptions", data);
dispatch("fetchCustomerData");
},
closeDialog({ commit }) { closeDialog({ commit }) {
commit("setDialog", false); commit("setDialog", false);
}, },
deleteCustomer({ dispatch, commit }, idList) { deleteCustomer({ dispatch, commit }, idList) {
confirm("Are you sure you want to delete this item?") && confirm("Are you sure you want to delete this item?") &&
idList.forEach((id) => { idList.forEach((id) => {
...@@ -72,20 +82,4 @@ export default { ...@@ -72,20 +82,4 @@ export default {
commit("setEditedItem", Object.assign({}, item)); commit("setEditedItem", Object.assign({}, item));
commit("setDialog", true); commit("setDialog", true);
}, },
filterCustomer({ getters, commit }, data) {
let x;
if (!data.searchInput) {
x = getters.customerList;
} else {
x = getters.customerList.filter((customer) => {
if (customer[data.filterColumn]) {
return customer[data.filterColumn]
.toLowerCase()
.includes(data.searchInput.toLowerCase());
}
});
}
commit("setfilteredCustomerList", x);
},
}; };
...@@ -46,7 +46,10 @@ export default { ...@@ -46,7 +46,10 @@ export default {
loading(state) { loading(state) {
return state.loading; return state.loading;
}, },
filteredCustomerList(state) { getOptions(state) {
return state.filteredCustomerList; return state.options;
},
totalCustomers(state) {
return state.totalCustomers;
}, },
}; };
export default { export default {
setCustomerList(state, data) { setCustomerList(state, data) {
state.customerList = data; state.customerList = data;
console.log("data", state.customerList);
}, },
setEditedIndex(state, index) { setEditedIndex(state, index) {
state.editedIndex = index; state.editedIndex = index;
...@@ -13,9 +14,12 @@ export default { ...@@ -13,9 +14,12 @@ export default {
}, },
setLoading(state, value) { setLoading(state, value) {
state.loading = value; state.loading = value;
console.log(value);
}, },
setfilteredCustomerList(state, data) { setOptions(state, data) {
state.filteredCustomerList = data; state.options = data;
},
setTotalCustomers(state, data) {
state.totalCustomers = data;
console.log(state.totalCustomers);
}, },
}; };
export default () => ({ export default () => ({
customerList: [], customerList: [],
filteredCustomerList: [],
editedIndex: -1, editedIndex: -1,
editedItem: {}, editedItem: {},
dialog: false, dialog: false,
loading: false, loading: false,
options: {},
totalCustomers: 0,
}); });
...@@ -62,7 +62,6 @@ export default { ...@@ -62,7 +62,6 @@ export default {
methods: { methods: {
...mapActions("products", [ ...mapActions("products", [
"fetchProductData", "fetchProductData",
"toggleSingleExpand",
"closeDialog", "closeDialog",
"deleteProduct", "deleteProduct",
"deleteMultiProduct", "deleteMultiProduct",
......
...@@ -345,28 +345,6 @@ ...@@ -345,28 +345,6 @@
} }
], ],
"products": [ "products": [
{
"id": "018ac742-5c12-4cf1-998c-28ea47a4169d",
"color": "maroon",
"department": "Health",
"price": "78.00",
"productName": "Gorgeous Frozen Sausages",
"type": "Unbranded",
"productDescription": "Ergonomic executive chair upholstered in bonded black leather and PVC padded seat and back for all-day comfort and support",
"productMaterial": "Steel",
"image": "http://loremflickr.com/640/480/food"
},
{
"id": "507f36d9-3f8d-4b51-954a-20ec632fb972",
"color": "ivory",
"department": "Beauty",
"price": "176.00",
"productName": "Tasty Granite Shoes",
"type": "Gorgeous",
"productDescription": "Carbonite web goalkeeper gloves are ergonomically designed to give easy fit",
"productMaterial": "Steel",
"image": "http://loremflickr.com/640/480/food"
},
{ {
"id": "fb4d2408-751f-4e07-856e-322dbed6f728", "id": "fb4d2408-751f-4e07-856e-322dbed6f728",
"color": "azure", "color": "azure",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment