vuetify: [Bug Report][3.3.11] VDataTable - Unable to set initial page

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/#…

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 17
  • Comments: 17 (3 by maintainers)

Commits related to this issue

Most upvoted comments

we need to fix it to implement this ability. Any help and PR are welcome

I can confirm that this is a bug and it’s present at least from August this year. The workaround with the items-length prop not only doesn’t fix anything, but completely messes up the pagination behavior

It practically makes using the table pagination in sync with url parameters impossible.

+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.

I can offer a temporary and very strange but working solution. If you add to your table @update:page="() => {}" then everything starts working correctly

playground

Yes I can confirm. Issue persist and datatable reset it always to 1 on mounting. I think this is easy fix

Still having this issue on 3.7.3

The only reliable way I’m able to avoid this bug seems to be setting a default of null instead of a number value.

<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 null no comparison to the page number can be made, so the page number’s value remains intact until items length is populated.

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.

<script setup>
import { ref } from 'vue';

const initialLoad = ref(true); // Flag to indicate initial load

async function updateOptions(params = {}) {
  if (initialLoad.value) { 
    initialLoad.value = false; // Disable after initial update
    params.page = getPage();   // Apply initial page setting
  }
  // ... (Rest of your update logic)
}
</script>

<template>
  <v-data-table 
    v-model:page="page"
    @update:options="updateOptions"
    ...>
    </v-data-table>
</template>

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?

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

Set the initial value of items-length prop to x * items-per-page where x is the page you want to start on.

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.