Skip to content

Commit 78b0e3c

Browse files
committed
fix(VDataTableVirtual): show index from virtualized items
1 parent b192e9f commit 78b0e3c

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
@@ -142,7 +142,7 @@ export const VDataTableRows = genericComponent<new <T>(
142142
}
143143

144144
const slotProps = {
145-
index,
145+
index: item._virtualIndex ?? index,
146146
item: item.raw,
147147
internalItem: item,
148148
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,
@@ -248,7 +255,7 @@ export const VDataTableVirtual = genericComponent<new <T extends readonly any[],
248255
{ ...itemSlotProps.props }
249256
ref={ itemRef }
250257
key={ itemSlotProps.internalItem.index }
251-
index={ itemSlotProps.internalItem.index }
258+
index={ itemSlotProps.index }
252259
v-slots={ slots }
253260
/>
254261
)

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)