-
-
Notifications
You must be signed in to change notification settings - Fork 7k
/
body.js
100 lines (87 loc) · 2.82 KB
/
body.js
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
import ExpandTransitionGenerator from '../../transitions/expand-transition'
export default {
methods: {
genTBody () {
const children = []
if (!this.itemsLength) {
const noData = this.$slots['no-data'] || this.noDataText
children.push(this.genEmptyBody(noData))
} else if (!this.filteredItems.length) {
const noResults = this.$slots['no-results'] || this.noResultsText
children.push(this.genEmptyBody(noResults))
} else {
children.push(this.genFilteredItems())
}
return this.$createElement('tbody', children)
},
genExpandedRow (props) {
const children = []
if (this.isExpanded(props.item)) {
const expand = this.$createElement('div', {
class: 'datatable__expand-content',
key: props.item[this.itemKey]
}, this.$scopedSlots.expand(props))
children.push(expand)
}
const transition = this.$createElement('transition-group', {
class: 'datatable__expand-col',
attrs: { colspan: '100%' },
props: {
tag: 'td'
},
on: ExpandTransitionGenerator('datatable__expand-col--expanded')
}, children)
return this.genTR([transition], { class: 'datatable__expand-row' })
},
createProps (item, index) {
const props = { item, index }
const key = this.itemKey
Object.defineProperty(props, 'selected', {
get: () => this.selected[item[this.itemKey]],
set: (value) => {
let selected = this.value.slice()
if (value) selected.push(item)
else selected = selected.filter(i => i[key] !== item[key])
this.$emit('input', selected)
}
})
Object.defineProperty(props, 'expanded', {
get: () => this.expanded[item[this.itemKey]],
set: (value) => {
if (!this.expand) {
Object.keys(this.expanded).forEach((key) => {
this.$set(this.expanded, key, false)
})
}
this.$set(this.expanded, item[this.itemKey], value)
}
})
return props
},
genFilteredItems () {
const rows = []
this.filteredItems.forEach((item, index) => {
const props = this.createProps(item, index)
const row = this.$scopedSlots.items
? this.$scopedSlots.items(props)
: []
rows.push(this.needsTR(row)
? this.genTR(row, {
attrs: { active: this.isSelected(item) }
})
: row)
if (this.$scopedSlots.expand) {
const expandRow = this.genExpandedRow(props)
rows.push(expandRow)
}
})
return rows
},
genEmptyBody (content) {
return this.genTR([this.$createElement('td', {
'class': 'text-xs-center',
attrs: { colspan: '100%' }
}, content)])
}
}
}