1
1
<script setup lang="ts">
2
- import
3
- {
4
- FlexRender ,
5
- getCoreRowModel ,
6
- getExpandedRowModel ,
7
- getGroupedRowModel ,
8
- useVueTable ,
9
- type ColumnDef ,
10
- type GroupingState ,
11
- type ExpandedState ,
12
- } from ' @tanstack/vue-table'
2
+ import {
3
+ FlexRender ,
4
+ getCoreRowModel ,
5
+ getExpandedRowModel ,
6
+ getGroupedRowModel ,
7
+ useVueTable ,
8
+ type ColumnDef ,
9
+ type GroupingState ,
10
+ type ExpandedState ,
11
+ } from ' @tanstack/vue-table'
13
12
import { ref } from ' vue'
14
13
15
14
// Define task type
@@ -77,14 +76,14 @@ const columns: ColumnDef<Task>[] = [
77
76
accessorKey: ' status' ,
78
77
header: ' Status' ,
79
78
enableGrouping: true ,
80
- accessorFn : ( row ) => row .status .name ,
79
+ accessorFn : row => row .status .name ,
81
80
cell : ({ row }) => row .original .status .name ,
82
81
},
83
82
{
84
83
accessorKey: ' priority' ,
85
84
header: ' Priority' ,
86
85
enableGrouping: true ,
87
- accessorFn : ( row ) => row .priority .name ,
86
+ accessorFn : row => row .priority .name ,
88
87
cell : ({ row }) => row .original .priority .name ,
89
88
},
90
89
{
@@ -118,13 +117,17 @@ const table = useVueTable({
118
117
return expanded .value
119
118
},
120
119
},
121
- onGroupingChange : ( updaterOrValue ) => {
120
+ onGroupingChange : updaterOrValue => {
122
121
grouping .value =
123
- typeof updaterOrValue === ' function' ? updaterOrValue (grouping .value ) : updaterOrValue
122
+ typeof updaterOrValue === ' function'
123
+ ? updaterOrValue (grouping .value )
124
+ : updaterOrValue
124
125
},
125
- onExpandedChange : ( updaterOrValue ) => {
126
+ onExpandedChange : updaterOrValue => {
126
127
expanded .value =
127
- typeof updaterOrValue === ' function' ? updaterOrValue (expanded .value ) : updaterOrValue
128
+ typeof updaterOrValue === ' function'
129
+ ? updaterOrValue (expanded .value )
130
+ : updaterOrValue
128
131
},
129
132
})
130
133
@@ -174,7 +177,11 @@ const clearGrouping = (): void => {
174
177
Group by Priority
175
178
</button >
176
179
177
- <button v-if =" grouping.length > 0" @click =" clearGrouping" class =" clear-button" >
180
+ <button
181
+ v-if =" grouping.length > 0"
182
+ @click =" clearGrouping"
183
+ class =" clear-button"
184
+ >
178
185
Clear Grouping
179
186
</button >
180
187
</div >
@@ -184,7 +191,10 @@ const clearGrouping = (): void => {
184
191
<table class =" data-table" >
185
192
<thead >
186
193
<tr >
187
- <th v-for =" header in table.getHeaderGroups()[0].headers" :key =" header.id" >
194
+ <th
195
+ v-for =" header in table.getHeaderGroups()[0].headers"
196
+ :key =" header.id"
197
+ >
188
198
{{ header.column.columnDef.header }}
189
199
</th >
190
200
</tr >
@@ -198,7 +208,10 @@ const clearGrouping = (): void => {
198
208
<td v-for =" cell in row.getVisibleCells()" :key =" cell.id" >
199
209
<!-- Grouped cell -->
200
210
<div v-if =" cell.getIsGrouped()" class =" grouped-cell" >
201
- <button class =" expand-button" @click =" toggleRowExpanded(row.id)" >
211
+ <button
212
+ class =" expand-button"
213
+ @click =" toggleRowExpanded(row.id)"
214
+ >
202
215
<span v-if =" expanded[row.id]" class =" icon" >👇</span >
203
216
<span v-else class =" icon" >👉</span >
204
217
<span class =" group-value" >{{ cell.getValue() }}</span >
@@ -216,14 +229,19 @@ const clearGrouping = (): void => {
216
229
217
230
<!-- Regular cell -->
218
231
<div v-else >
219
- <FlexRender :render =" cell.column.columnDef.cell" :props =" cell.getContext()" />
232
+ <FlexRender
233
+ :render =" cell.column.columnDef.cell"
234
+ :props =" cell.getContext()"
235
+ />
220
236
</div >
221
237
</td >
222
238
</tr >
223
239
224
240
<!-- Empty state -->
225
241
<tr v-if =" table.getRowModel().rows.length === 0" >
226
- <td :colspan =" columns.length" class =" empty-table" >No tasks found.</td >
242
+ <td :colspan =" columns.length" class =" empty-table" >
243
+ No tasks found.
244
+ </td >
227
245
</tr >
228
246
</tbody >
229
247
</table >
0 commit comments