Skip to content

Commit 29e3f09

Browse files
authored
fix(VDataTableVirtual): show index from virtualized items (#22324)
fixes #19108
1 parent 3c3f667 commit 29e3f09

File tree

3 files changed

+11
-3
lines changed

3 files changed

+11
-3
lines changed

packages/vuetify/src/components/VDataTable/VDataTableRows.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ export const VDataTableRows = genericComponent<new <T>(
143143
}
144144

145145
const slotProps = {
146-
index,
146+
index: item.virtualIndex ?? index,
147147
item: item.raw,
148148
internalItem: item,
149149
columns: columns.value,

packages/vuetify/src/components/VDataTable/VDataTableVirtual.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,14 @@ export const VDataTableVirtual = genericComponent<new <T extends readonly any[],
141141
calculateVisibleItems,
142142
scrollToIndex,
143143
} = useVirtual(props, flatItems)
144-
const displayItems = computed(() => computedItems.value.map(item => item.raw))
144+
145+
const displayItems = computed(() =>
146+
computedItems.value
147+
.map(item => ({
148+
...item.raw,
149+
virtualIndex: item.index,
150+
}))
151+
)
145152

146153
useOptions({
147154
sortBy,
@@ -249,7 +256,7 @@ export const VDataTableVirtual = genericComponent<new <T extends readonly any[],
249256
{ ...itemSlotProps.props }
250257
ref={ itemRef }
251258
key={ itemSlotProps.internalItem.index }
252-
index={ itemSlotProps.internalItem.index }
259+
index={ itemSlotProps.index }
253260
v-slots={ slots }
254261
/>
255262
)

packages/vuetify/src/components/VDataTable/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ export type InternalDataTableHeader = Omit<DataTableHeader, 'key' | 'value' | 'c
4949
export interface DataTableItem<T = any> extends Omit<InternalItem<T>, 'type'>, GroupableItem<T>, SelectableItem {
5050
key: any
5151
index: number
52+
virtualIndex?: number
5253
columns: {
5354
[key: string]: any
5455
}

0 commit comments

Comments
 (0)