forked from quasarframework/quasar
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtable-column-selection.js
More file actions
81 lines (69 loc) · 2.11 KB
/
table-column-selection.js
File metadata and controls
81 lines (69 loc) · 2.11 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
import { isNumber } from '../../utils/is.js'
export default {
props: {
visibleColumns: Array
},
computed: {
colList () {
if (this.columns !== void 0) {
return this.columns
}
// we infer columns from first row
const row = this.data[0]
return row !== void 0
? Object.keys(row).map(name => ({
name,
label: name.toUpperCase(),
field: name,
align: isNumber(row[name]) ? 'right' : 'left',
sortable: true
}))
: []
},
computedCols () {
const { sortBy, descending } = this.computedPagination
const cols = this.visibleColumns !== void 0
? this.colList.filter(col => col.required === true || this.visibleColumns.includes(col.name) === true)
: this.colList
return cols.map(col => {
const align = col.align || 'right'
const alignClass = `text-${align}`
return {
...col,
align,
__iconClass: `q-table__sort-icon q-table__sort-icon--${align}`,
__thClass: alignClass +
(col.headerClasses !== void 0 ? ' ' + col.headerClasses : '') +
(col.sortable === true ? ' sortable' : '') +
(col.name === sortBy ? ` sorted ${descending === true ? 'sort-desc' : ''}` : ''),
__tdStyle: col.style !== void 0
? (
typeof col.style !== 'function'
? () => col.style
: col.style
)
: () => null,
__tdClass: col.classes !== void 0
? (
typeof col.classes !== 'function'
? () => alignClass + ' ' + col.classes
: row => alignClass + ' ' + col.classes(row)
)
: () => alignClass
}
})
},
computedColsMap () {
const names = {}
this.computedCols.forEach(col => {
names[col.name] = col
})
return names
},
computedColspan () {
return this.tableColspan !== void 0
? this.tableColspan
: this.computedCols.length + (this.hasSelectionMode === true ? 1 : 0)
}
}
}