@@ -13,16 +13,41 @@ import { useGroupBy } from './composables/group'
1313import { genericComponent , useRender } from '@/util'
1414
1515// Types
16- import type { DataTableItem , InternalDataTableItem } from './types'
16+ import type { DataTableItem , GroupHeaderItem , InternalDataTableHeader , InternalDataTableItem } from './types'
1717import type { PropType } from 'vue'
1818
19+ type GroupHeaderSlot = {
20+ index : number
21+ item : GroupHeaderItem
22+ columns : InternalDataTableHeader [ ]
23+ isExpanded : ( item : DataTableItem ) => boolean
24+ toggleExpand : ( item : DataTableItem ) => void
25+ isSelected : ( items : DataTableItem [ ] ) => boolean
26+ toggleSelect : ( item : DataTableItem ) => void
27+ toggleGroup : ( group : GroupHeaderItem ) => void
28+ isGroupOpen : ( group : GroupHeaderItem ) => boolean
29+ }
30+
31+ type ItemSlot = {
32+ index : number
33+ item : InternalDataTableItem
34+ columns : InternalDataTableHeader [ ]
35+ isExpanded : ( item : DataTableItem ) => boolean
36+ toggleExpand : ( item : DataTableItem ) => void
37+ isSelected : ( items : DataTableItem [ ] ) => boolean
38+ toggleSelect : ( item : DataTableItem ) => void
39+ }
40+
1941export type VDataTableRowsSlots = {
2042 default : [ ]
21- item : [ InternalDataTableItem ]
43+ item : [ ItemSlot ]
2244 loading : [ ]
23- 'group-header' : [ InternalDataTableItem ]
45+ 'group-header' : [ GroupHeaderSlot ]
2446 'no-data' : [ ]
25- }
47+ 'expanded-row' : [ ItemSlot ]
48+ 'item.data-table-select' : [ ItemSlot ]
49+ 'item.data-table-expand' : [ ItemSlot ]
50+ } & { [ key : `item.${string } `] : [ ItemSlot ] }
2651
2752export const VDataTableRows = genericComponent < VDataTableRowsSlots > ( ) ( {
2853 name : 'VDataTableRows' ,
@@ -88,7 +113,7 @@ export const VDataTableRows = genericComponent<VDataTableRowsSlots>()({
88113 toggleSelect,
89114 toggleGroup,
90115 isGroupOpen,
91- } ) : (
116+ } as GroupHeaderSlot ) : (
92117 < VDataTableGroupHeaderRow
93118 key = { `group-header_${ item . id } ` }
94119 item = { item }
@@ -97,17 +122,19 @@ export const VDataTableRows = genericComponent<VDataTableRowsSlots>()({
97122 )
98123 }
99124
125+ const slotProps = {
126+ index,
127+ item,
128+ columns : columns . value ,
129+ isExpanded,
130+ toggleExpand,
131+ isSelected,
132+ toggleSelect,
133+ } as ItemSlot
134+
100135 return (
101136 < >
102- { slots . item ? slots . item ( {
103- index,
104- item,
105- columns : columns . value ,
106- isExpanded,
107- toggleExpand,
108- isSelected,
109- toggleSelect,
110- } ) : (
137+ { slots . item ? slots . item ( slotProps ) : (
111138 < VDataTableRow
112139 key = { `item_${ item . value } ` }
113140 onClick = { ( event : Event ) => {
@@ -122,7 +149,7 @@ export const VDataTableRows = genericComponent<VDataTableRowsSlots>()({
122149 />
123150 ) }
124151
125- { isExpanded ( item ) && slots [ 'expanded-row' ] ?.( { item , columns : columns . value } ) }
152+ { isExpanded ( item ) && slots [ 'expanded-row' ] ?.( slotProps ) }
126153 </ >
127154 )
128155 } ) }
0 commit comments