9
9
<thead :class =" ui.thead" >
10
10
<tr :class =" ui.tr.base" >
11
11
<th v-if =" modelValue" scope =" col" :class =" ui.checkbox.padding" >
12
- <UCheckbox :model-value =" indeterminate || selected.length === rows.length" :indeterminate =" indeterminate" v-bind =" ui.default.checkbox" aria-label =" Select all" @change =" onChange" />
12
+ <UCheckbox
13
+ :model-value =" indeterminate || selected.length === rows.length"
14
+ :indeterminate =" indeterminate"
15
+ v-bind =" ui.default.checkbox"
16
+ aria-label =" Select all"
17
+ @change =" onChange"
18
+ />
13
19
</th >
14
20
15
21
<th v-if =" $slots.expand" scope =" col" :class =" ui.tr.base" >
73
79
<template v-for =" (row , index ) in rows " :key =" index " >
74
80
<tr :class =" [ui.tr.base, isSelected(row) && ui.tr.selected, $attrs.onSelect && ui.tr.active, row?.class]" @click =" () => onSelect(row)" >
75
81
<td v-if =" modelValue" :class =" ui.checkbox.padding" >
76
- <UCheckbox v-model =" selected" :value =" row" v-bind =" ui.default.checkbox" aria-label =" Select row" @click.capture.stop =" () => onSelect(row)" />
82
+ <UCheckbox
83
+ :model-value =" isSelected(row)"
84
+ v-bind =" ui.default.checkbox"
85
+ aria-label =" Select row"
86
+ @change =" onChangeCheckbox($event, row)"
87
+ @click.capture.stop =" () => onSelect(row)"
88
+ />
77
89
</td >
78
90
79
91
<td
@@ -129,7 +141,7 @@ import { table } from '#ui/ui.config'
129
141
const config = mergeConfig <typeof table >(appConfig .ui .strategy , appConfig .ui .table , table )
130
142
131
143
function defaultComparator<T > (a : T , z : T ): boolean {
132
- return a === z
144
+ return JSON . stringify ( a ) === JSON . stringify ( z )
133
145
}
134
146
135
147
function defaultSort (a : any , b : any , direction : ' asc' | ' desc' ) {
@@ -284,7 +296,7 @@ export default defineComponent({
284
296
return props .by (a , z )
285
297
}
286
298
287
- function isSelected (row ) {
299
+ function isSelected (row : TableRow ) {
288
300
if (! props .modelValue ) {
289
301
return false
290
302
}
@@ -306,7 +318,7 @@ export default defineComponent({
306
318
}
307
319
}
308
320
309
- function onSelect (row ) {
321
+ function onSelect (row : TableRow ) {
310
322
if (! $attrs .onSelect ) {
311
323
return
312
324
}
@@ -338,7 +350,16 @@ export default defineComponent({
338
350
}
339
351
}
340
352
341
- function getRowData (row : Object , rowKey : string | string [], defaultValue : any = ' ' ) {
353
+ function onChangeCheckbox (checked : boolean , row : TableRow ) {
354
+ if (checked ) {
355
+ selected .value .push (row )
356
+ } else {
357
+ const index = selected .value .findIndex ((item ) => compare (item , row ))
358
+ selected .value .splice (index , 1 )
359
+ }
360
+ }
361
+
362
+ function getRowData (row : TableRow , rowKey : string | string [], defaultValue : any = ' ' ) {
342
363
return get (row , rowKey , defaultValue )
343
364
}
344
365
@@ -386,6 +407,7 @@ export default defineComponent({
386
407
emptyState ,
387
408
// eslint-disable-next-line vue/no-dupe-keys
388
409
loadingState ,
410
+ onChangeCheckbox ,
389
411
openedRows ,
390
412
isSelected ,
391
413
onSort ,
@@ -397,4 +419,4 @@ export default defineComponent({
397
419
}
398
420
}
399
421
})
400
- </script >
422
+ </script >
0 commit comments