Skip to content

Conversation

@hdJerry
Copy link
Contributor

@hdJerry hdJerry commented Oct 28, 2025

Summary

Fixes an issue where VDataTableVirtual selected the wrong range of items when holding Shift while the table was sorted by a specific column.

Fix

Used the actual index based on the item position in the array and not the index in the item itself

<template>
  <v-app>
    <v-main>
      <v-container>
        <v-card>
          <v-data-table-virtual
            v-model="selected"
            :headers="headers"
            :items="items"
            :sort-by="[{ key: 'name', order: 'asc' }]"
            item-value="id"
            show-select
            height="400"
          />
          <v-card-text> <b>Selected IDs:</b> {{ selected }} </v-card-text>
        </v-card>
      </v-container>
    </v-main>
  </v-app>
</template>

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


  const selected = ref([])

  const headers = [
    { title: 'ID', value: 'id', width: '100px' },
    { title: 'Name', value: 'name' },
  ]

  // A simple dataset
  const items = Array.from({ length: 100 }, (_, i) => ({
    id: i + 1, // Unique ID
    name: `User ${i + 1}`,
  }))
</script>

Closes #22220

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug Report] VDataTableVirtual with sort-by selects incorrect items when holding shift

1 participant