forked from quasarframework/quasar
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtable-body.js
More file actions
112 lines (102 loc) · 3.18 KB
/
table-body.js
File metadata and controls
112 lines (102 loc) · 3.18 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
import extend from '../../utils/extend'
import { QCheckbox } from '../checkbox'
export default {
methods: {
getTableBody (h) {
const
body = this.$scopedSlots.body,
bodyCell = this.$scopedSlots['body-cell'],
topRow = this.$scopedSlots['top-row'],
bottomRow = this.$scopedSlots['bottom-row']
let
child = []
if (body) {
child = this.computedRows.map(row => {
const
key = row[this.rowKey],
selected = this.isRowSelected(key)
return body(this.addBodyRowMeta({
key,
row,
cols: this.computedCols,
colsMap: this.computedColsMap,
__trClass: selected ? 'selected' : ''
}))
})
}
else {
child = this.computedRows.map(row => {
const
key = row[this.rowKey],
selected = this.isRowSelected(key),
child = bodyCell
? this.computedCols.map(col => bodyCell(this.addBodyCellMetaData({ row, col: col })))
: this.computedCols.map(col => {
const slot = this.$scopedSlots[`body-cell-${col.name}`]
return slot
? slot(this.addBodyCellMetaData({ row, col: col }))
: h('td', { staticClass: col.__tdClass }, this.getCellValue(col, row))
})
if (this.hasSelectionMode) {
child.unshift(h('td', { staticClass: 'q-table-col-auto-width' }, [
h(QCheckbox, {
props: {
value: selected,
color: this.color,
dark: this.dark
},
on: {
input: adding => {
this.__updateSelection([key], [row], adding)
}
}
})
]))
}
return h('tr', { key, 'class': { selected } }, child)
})
}
if (topRow) {
child.unshift(topRow({cols: this.computedCols}))
}
if (bottomRow) {
child.push(bottomRow({cols: this.computedCols}))
}
return h('tbody', child)
},
addBodyRowMeta (data) {
if (this.hasSelectionMode) {
Object.defineProperty(data, 'selected', {
get: () => this.isRowSelected(data.key),
set: adding => {
this.__updateSelection([data.key], [data.row], adding)
}
})
}
Object.defineProperty(data, 'expand', {
get: () => this.rowsExpanded[data.key] === true,
set: val => {
this.$set(this.rowsExpanded, data.key, val)
}
})
data.cols = data.cols.map(col => {
const c = extend({}, col)
Object.defineProperty(c, 'value', {
get: () => this.getCellValue(col, data.row)
})
return c
})
return data
},
addBodyCellMetaData (data) {
Object.defineProperty(data, 'value', {
get: () => this.getCellValue(data.col, data.row)
})
return data
},
getCellValue (col, row) {
const val = typeof col.field === 'function' ? col.field(row) : row[col.field]
return col.format ? col.format(val) : val
}
}
}