Skip to content

Commit

Permalink
✨ Make url query params sync with table query.
Browse files Browse the repository at this point in the history
NOTE: Use of v-skeleton-loader. If you don't do this the v-data-table-server component will reset the page value on load. See vuetifyjs/vuetify#17966
  • Loading branch information
klondikemarlen committed Mar 13, 2024
1 parent 908bd57 commit fe84016
Showing 1 changed file with 26 additions and 4 deletions.
30 changes: 26 additions & 4 deletions web/src/components/users/UsersEditTable.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
<template>
<v-skeleton-loader
v-if="isLoading"
type="table"
/>
<v-data-table-server
v-else
v-model:items-per-page="itemsPerPage"
v-model:page="page"
:headers="headers"
Expand Down Expand Up @@ -85,14 +90,15 @@ const headers = ref([
const route = useRoute()
const router = useRouter()
const itemsPerPage = ref(10)
const page = ref(1)
const datasetsQuery = computed(() => ({
const itemsPerPage = ref(parseInt(route.query.perPage as string) || 10)
const page = ref(parseInt(route.query.page as string) || 1)
const usersQuery = computed(() => ({
perPage: itemsPerPage.value,
page: page.value,
}))
const { users, totalCount, isLoading, refresh } = useUsers(datasetsQuery)
const { users, totalCount, isLoading, refresh } = useUsers(usersQuery)
function goToUserEdit(userId: number) {
router.push({
Expand All @@ -119,6 +125,22 @@ function showDeleteDialogForRouteQuery() {
showDeleteDialog(user)
}
watch(
() => [page.value, itemsPerPage.value],
([newPage, newPerPage]) => {
router.push({
query: {
...route.query,
page: newPage,
perPage: newPerPage,
},
})
},
{
immediate: true,
}
)
watch(
() => users.value,
(users) => {
Expand Down

0 comments on commit fe84016

Please sign in to comment.