-
-
Notifications
You must be signed in to change notification settings - Fork 7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Bug Report][3.3.11] VDataTable - Unable to set initial page #17966
[Bug Report][3.3.11] VDataTable - Unable to set initial page #17966
Comments
Yes I can confirm. Issue persist and datatable reset it always to 1 on mounting. I think this is easy fix |
Set the initial value of I'm not sure if we should call this a bug or not. Maaybe we'd want different behavior in -server variant. I'll keep this open for now. |
I can confirm that this is a bug and it's present at least from August this year. The workaround with the It practically makes using the table pagination in sync with url parameters impossible. |
I can offer a temporary and very strange but working solution. If you add to your table |
vuetify 3.4.9 and still not fixed 😒 btw U can bring back options prop to VDataTable. Now with only update:options event is confusing, especially when U migrate from vue 2 |
Except of page change, unfortunately |
I really appreciate your work but i have to say I really don't understand how this is labeled as maybe. How are we supposed to save the pagination in the navigation if the table keeps resetting to the first page? |
we need to fix it to implement this ability. |
+1 on this. I cant initialise a table on any page other than 1. Workaround: Don't render the table until you have loaded the data. Use a skeleton load while you wait. |
Thanks @naglafar. I can confirm that, "delaying render until after loading completes", works for me. <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"
:items="items"
:items-length="totalCount"
:loading="isLoading"
/>
</template> Assuming items are loaded like async function fetch() {
isLoading.value = true
try {
items.value = await fetchSomeItems()
} finally {
isLoading.value = false
}
} where EDIT: see icefoganalytics/internal-data-portal@fe84016 for full example. |
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
Is this just a bug in
Should it be something like |
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 The UI related to this is pretty bad, as it causes flicker, but at least the but is avoided.
Solution: ignore page change while loading. This is a better fix for: > 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
I've found a work-around for the flicker introduced by using v-if with a skeleton loader. <template>
<v-data-table-server
v-model:items-per-page="itemsPerPage"
:page="page"
:headers="headers"
:items="items"
:items-length="totalCount"
:loading="isLoading"
@update:page="updatePage"
/>
</template>
<script setup lang="ts">
// ... other code and variable setup
function updatePage(newPage: number) {
if (isLoading.value) return
page.value = newPage
}
async function fetch() {
isLoading.value = true
try {
items.value = await fetchSomeItems()
} finally {
isLoading.value = false
}
}
</script> |
Solution: ignore page change while loading. This is a better work-around for: > 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
fixes #17966 Co-authored-by: John Leider <[email protected]>
Still have this issue as of 3.6.9 |
I've implemented a solution where an initializing value is used to bypass the first @update:options="updateOptions" event. This prevents unintended modifications during the initial table setup.
|
One way that could work for some people is to use a watcher instead of listening to the <v-data-table-server
v-model:page="options.page"
v-model:items-per-page="options.itemsPerPage"
/>
const options = ref({
page: 1,
itemsPerPage: 10,
});
watch(options, value => {
// Fetch your data.
},
{ deep: true }
) This allows you to check the query in onMounted(() => {
// Pseudo code. This will trigger the watcher only once
options.value = {
page: query.page,
itemsPerPage: query.itemsPerPage
}
}); Here is a playground demonstrating what I mean: Playground |
Still having this issue. What is the status here? @webdevnerdstuff's PR does not seem to resolve the issue as far as I can tell. |
Still having this issue on The only reliable way I'm able to avoid this bug seems to be setting a default of <template>
<v-data-table-server
:items-length="itemsLength"
:page="page"
>
</v-data-table-server>
</template>
<script setup>
import { ref } from 'vue';
const itemsLength = ref(null);
const page = ref(1);
</script> I believe this works because when items length is |
Environment
Vuetify Version: 3.3.11
Vue Version: 3.3.4
Browsers: Firefox 117.0
OS: Linux x86_64
Steps to reproduce
Set the
page
prop to something other than 1. (e.g. from a URL query parameter)Expected Behavior
Table displays the given page of the table.
Actual Behavior
The
page
prop is always changed back to 1 on load.Reproduction Link
https://play.vuetifyjs.com/#...
The text was updated successfully, but these errors were encountered: