[chore] add server side filtering for getDrinks

This commit is contained in:
Tim Gröger 2021-11-13 13:24:02 +01:00
parent 955f777aac
commit ab92f16177
2 changed files with 14 additions and 5 deletions

View File

@ -8,10 +8,10 @@
row-key="id" row-key="id"
grid grid
:loading="loading" :loading="loading"
:filter="search"
@request="onRequest" @request="onRequest"
> >
<!-- <!--
:filter="search"
:filter-method="filter" :filter-method="filter"
--> -->
<template #top-right> <template #top-right>
@ -328,7 +328,7 @@ export default defineComponent({
}); });
return retVal; return retVal;
}, },
filterable: true, filterable: false,
sortable: false, sortable: false,
public: false, public: false,
}, },
@ -393,10 +393,10 @@ export default defineComponent({
const loading = ref(false); const loading = ref(false);
async function onRequest(props: { pagination: PaginationInterface; filter?: string }) { async function onRequest(props: { pagination: PaginationInterface; filter?: Search }) {
const { page, rowsPerPage, sortBy, descending } = props.pagination; const { page, rowsPerPage, sortBy, descending } = props.pagination;
loading.value = true; loading.value = true;
console.log('search_keys', search_keys);
const fetchCount = rowsPerPage === 0 ? pagination.value.rowsNumber : rowsPerPage; const fetchCount = rowsPerPage === 0 ? pagination.value.rowsNumber : rowsPerPage;
const startRow = (page - 1) * rowsPerPage; const startRow = (page - 1) * rowsPerPage;
try { try {
@ -404,6 +404,8 @@ export default defineComponent({
offset: startRow, offset: startRow,
limit: fetchCount, limit: fetchCount,
descending, descending,
search_name: props.filter.value,
search_key: props.filter.key,
}); });
pagination.value.page = page; pagination.value.page = page;
pagination.value.rowsPerPage = rowsPerPage; pagination.value.rowsPerPage = rowsPerPage;

View File

@ -138,8 +138,15 @@ export const usePricelistStore = defineStore({
this.extraIngredients.splice(index, 1); this.extraIngredients.splice(index, 1);
} }
}, },
async getDrinks(filter: { limit?: number; offset?: number; descending?: boolean }) { async getDrinks(filter: {
limit?: number;
offset?: number;
descending?: boolean;
search_name?: string;
search_key?: string;
}) {
if (!filter) filter = { limit: 10 }; if (!filter) filter = { limit: 10 };
console.log('filter_api', filter);
const { data } = await api.get<Array<FG.Drink>>('pricelist/drinks', { const { data } = await api.get<Array<FG.Drink>>('pricelist/drinks', {
params: filter, params: filter,
}); });