Skip to content
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

fix(VDataTable): correct check for old search value #20185

Conversation

webdevnerdstuff
Copy link
Contributor

@webdevnerdstuff webdevnerdstuff commented Jul 17, 2024

Description

fixes: #17966

Markup:

<template>
  <v-data-table-server
    v-model:items-per-page="itemsPerPage"
    :headers="headers"
    :items="serverItems"
    :items-length="totalItems"
    :loading="loading"
    item-value="name"
    page="2"
    @update:options="loadItems"
  />
</template>

<script>
  const desserts = [
    {
      name: 'Frozen Yogurt',
      calories: 159,
      fat: 6.0,
      carbs: 24,
      protein: 4.0,
      iron: '1',
    },
    {
      name: 'Jelly bean',
      calories: 375,
      fat: 0.0,
      carbs: 94,
      protein: 0.0,
      iron: '0',
    },
    {
      name: 'KitKat',
      calories: 518,
      fat: 26.0,
      carbs: 65,
      protein: 7,
      iron: '6',
    },
    {
      name: 'Eclair',
      calories: 262,
      fat: 16.0,
      carbs: 23,
      protein: 6.0,
      iron: '7',
    },
    {
      name: 'Gingerbread',
      calories: 356,
      fat: 16.0,
      carbs: 49,
      protein: 3.9,
      iron: '16',
    },
    {
      name: 'Ice cream sandwich',
      calories: 237,
      fat: 9.0,
      carbs: 37,
      protein: 4.3,
      iron: '1',
    },
    {
      name: 'Lollipop',
      calories: 392,
      fat: 0.2,
      carbs: 98,
      protein: 0,
      iron: '2',
    },
    {
      name: 'Cupcake',
      calories: 305,
      fat: 3.7,
      carbs: 67,
      protein: 4.3,
      iron: '8',
    },
    {
      name: 'Honeycomb',
      calories: 408,
      fat: 3.2,
      carbs: 87,
      protein: 6.5,
      iron: '45',
    },
    {
      name: 'Donut',
      calories: 452,
      fat: 25.0,
      carbs: 51,
      protein: 4.9,
      iron: '22',
    },
  ]

  const FakeAPI = {
    async fetch ({ page, itemsPerPage, sortBy }) {
      return new Promise(resolve => {
        setTimeout(() => {
          const start = (page - 1) * itemsPerPage
          const end = start + itemsPerPage
          const items = desserts.slice()

          if (sortBy.length) {
            const sortKey = sortBy[0].key
            const sortOrder = sortBy[0].order
            items.sort((a, b) => {
              const aValue = a[sortKey]
              const bValue = b[sortKey]
              return sortOrder === 'desc' ? bValue - aValue : aValue - bValue
            })
          }

          const paginated = items.slice(start, end)

          resolve({ items: paginated, total: items.length })
        }, 500)
      })
    },
  }

  export default {
    data: () => ({
      itemsPerPage: 5,
      headers: [
        {
          title: 'Dessert (100g serving)',
          align: 'start',
          sortable: false,
          key: 'name',
        },
        { title: 'Calories', key: 'calories', align: 'end' },
        { title: 'Fat (g)', key: 'fat', align: 'end' },
        { title: 'Carbs (g)', key: 'carbs', align: 'end' },
        { title: 'Protein (g)', key: 'protein', align: 'end' },
        { title: 'Iron (%)', key: 'iron', align: 'end' },
      ],
      serverItems: [],
      loading: true,
      totalItems: 0,
    }),
    methods: {
      loadItems ({ page, itemsPerPage, sortBy }) {
        this.loading = true
        FakeAPI.fetch({ page, itemsPerPage, sortBy }).then(({ items, total }) => {
          this.serverItems = items
          this.totalItems = total
          this.loading = false
        })
      },
    },
  }
</script>

@johnleider johnleider added this to the v3.6.x milestone Jul 17, 2024
@johnleider johnleider added T: bug Functionality that does not work as intended/expected C: VDataTable VDatatable labels Jul 17, 2024
Copy link
Contributor

🚀 Nightly release published to @vuetify/nightly@3.6.13-pr-20185.5bf1ff4.

@KaelWD
Copy link
Member

KaelWD commented Jul 31, 2024

This doesn't fix it, still on page 1 initially: https://play.vuetifyjs.com/#eNqNV9tu4zYQ/RXCQGG5tRT5mkSI027Tpk1ToHkoChRJHmh5YgtLiwJFedcb+N93SJGiJCuw/RDTM2eGh3Mj8/zey0V88SnLgl0Bvah3I2GbMSrh9iUl5Gbnr6ikvqRLBn4OYgdCyQnZ+Vu+AhYliM/9DISf0TUsXnpa8ATiCX++9EpwtAG6ApGj2qwqTWnPIF3LDaoll5Q9KFkTgapy96aOcbpK0jVqzarS5EBFrDyWC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+bRGhIts7ZGOWXdQ8zyPiBSFy4977bsb9DAwiy3IDV+hpqqY6pV9/jAu24szCBhfe/3KAx5Peaj1hNwk2CslTexBxdMpzc0QnHUVBHIDqVevQdukpjMVw+MppgnU4mcHQQfKxU0xVT86QO4suilaE8gu3RBo3IuIuLmo/jvpHYZpwZj+8/odThMJjw==

@KaelWD KaelWD force-pushed the master branch 2 times, most recently from e20cfec to 2766105 Compare August 15, 2024 09:17
@KaelWD KaelWD modified the milestones: v3.6.x, v3.7.x Aug 15, 2024
@KaelWD KaelWD force-pushed the master branch 3 times, most recently from 4c970f9 to 6a3285f Compare September 3, 2024 18:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C: VDataTable VDatatable T: bug Functionality that does not work as intended/expected
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug Report][3.3.11] VDataTable - Unable to set initial page
3 participants