forked from quasarframework/quasar
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtable-row-selection.js
More file actions
76 lines (64 loc) · 1.64 KB
/
table-row-selection.js
File metadata and controls
76 lines (64 loc) · 1.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
export default {
props: {
selection: {
type: String,
default: 'none',
validator: v => ['single', 'multiple', 'none'].includes(v)
},
selected: {
type: Array,
default: () => []
}
},
computed: {
selectedKeys () {
const keys = {}
this.selected.map(this.getRowKey).forEach(key => {
keys[key] = true
})
return keys
},
hasSelectionMode () {
return this.selection !== 'none'
},
singleSelection () {
return this.selection === 'single'
},
multipleSelection () {
return this.selection === 'multiple'
},
allRowsSelected () {
return this.computedRows.length > 0 && this.computedRows.every(
row => this.selectedKeys[ this.getRowKey(row) ] === true
)
},
someRowsSelected () {
return this.allRowsSelected !== true &&
this.computedRows.some(row => this.selectedKeys[ this.getRowKey(row) ] === true)
},
rowsSelectedNumber () {
return this.selected.length
}
},
methods: {
isRowSelected (key) {
return this.selectedKeys[key] === true
},
clearSelection () {
this.$emit('update:selected', [])
},
__updateSelection (keys, rows, added, evt) {
this.$emit('selection', { rows, added, keys, evt })
const payload = this.singleSelection === true
? (added === true ? rows : [])
: (
added === true
? this.selected.concat(rows)
: this.selected.filter(
row => keys.includes(this.getRowKey(row)) === false
)
)
this.$emit('update:selected', payload)
}
}
}