add filter to search user

This commit is contained in:
Tim Gröger 2023-05-03 14:04:40 +02:00
parent db4f3c45c4
commit a52ab890e0
2 changed files with 94 additions and 74 deletions

View File

@ -1,9 +1,20 @@
<template> <template>
<div>
<q-page padding> <q-page padding>
<q-table v-model:pagination="pagination" :rows="rows" row-key="userid" :columns="columns" @request="onRequest"> <q-table
v-model:pagination="pagination"
:rows="rows"
row-key="userid"
:columns="columns"
@request="onRequest"
:filter="filter"
>
<template #top-right> <template #top-right>
<div class="full-width row q-gutter-sm"> <div class="full-width row q-gutter-sm">
<q-input v-model="filter" label="Filter" filled dense debounce="300">
<template v-slot:append>
<q-icon name="mdi-magnify" />
</template>
</q-input>
<q-input v-model.number="limit" label="Limit" type="number" step="0.01" suffix="€" filled dense /> <q-input v-model.number="limit" label="Limit" type="number" step="0.01" suffix="€" filled dense />
<q-btn label="Limits Setzen" color="primary" dense @click="setLimits(limit)" /> <q-btn label="Limits Setzen" color="primary" dense @click="setLimits(limit)" />
</div> </div>
@ -70,7 +81,6 @@
</template> </template>
</q-table> </q-table>
</q-page> </q-page>
</div>
</template> </template>
<script lang="ts"> <script lang="ts">
@ -92,11 +102,12 @@ export default defineComponent({
onBeforeMount(() => { onBeforeMount(() => {
void userStore.getUsers(); void userStore.getUsers();
void store.getLimits(); void store.getLimits();
void onRequest({ pagination: pagination.value, filter: undefined }); void onRequest({ pagination: pagination.value, filter: filter.value });
}); });
const rows = computed(() => store.balances); const rows = computed(() => store.balances);
const limit = ref<number>(); const limit = ref<number>();
const filter = ref<string>();
const columns = [ const columns = [
{ {
@ -151,6 +162,7 @@ export default defineComponent({
async function onRequest(props: { pagination: PaginationInterface; filter?: string }) { async function onRequest(props: { pagination: PaginationInterface; filter?: string }) {
const { page, rowsPerPage, sortBy, descending } = props.pagination; const { page, rowsPerPage, sortBy, descending } = props.pagination;
const filter = props.filter;
loading.value = true; loading.value = true;
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;
@ -161,6 +173,7 @@ export default defineComponent({
offset: startRow, offset: startRow,
descending: descending ? true : undefined, descending: descending ? true : undefined,
sortBy, sortBy,
filter,
}); });
pagination.value.page = page; pagination.value.page = page;
pagination.value.rowsPerPage = rowsPerPage; pagination.value.rowsPerPage = rowsPerPage;
@ -231,6 +244,7 @@ export default defineComponent({
onRequest, onRequest,
getFirstname, getFirstname,
getLastname, getLastname,
filter,
}; };
}, },
}); });

View File

@ -77,7 +77,13 @@ export const useBalanceStore = defineStore({
return data; return data;
}, },
async getBalances(filter?: { limit?: number; offset?: number; sortBy?: string; descending?: boolean }) { async getBalances(filter?: {
limit?: number;
offset?: number;
sortBy?: string;
descending?: boolean;
filter?: string;
}) {
const { data } = await api.get<{ balances: BalancesResponse[]; count: number }>('/balance', { const { data } = await api.get<{ balances: BalancesResponse[]; count: number }>('/balance', {
params: filter, params: filter,
}); });