forked from quasarframework/quasar
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQTable.js
More file actions
190 lines (177 loc) · 4.65 KB
/
QTable.js
File metadata and controls
190 lines (177 loc) · 4.65 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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
import Top from './table-top.js'
import TableHeader from './table-header.js'
import TableBody from './table-body.js'
import Bottom from './table-bottom.js'
import Sort from './table-sort.js'
import Filter from './table-filter.js'
import Pagination from './table-pagination.js'
import RowSelection from './table-row-selection.js'
import ColumnSelection from './table-column-selection.js'
import Expand from './table-expand.js'
import FullscreenMixin from '../../mixins/fullscreen.js'
export default {
name: 'QTable',
mixins: [
FullscreenMixin,
Top,
TableHeader,
TableBody,
Bottom,
Sort,
Filter,
Pagination,
RowSelection,
ColumnSelection,
Expand
],
props: {
data: {
type: Array,
default: () => []
},
rowKey: {
type: String,
default: 'id'
},
color: {
type: String,
default: 'grey-8'
},
grid: Boolean,
dense: Boolean,
columns: Array,
loading: Boolean,
title: String,
hideHeader: Boolean,
hideBottom: Boolean,
dark: Boolean,
separator: {
type: String,
default: 'horizontal',
validator: v => ['horizontal', 'vertical', 'cell', 'none'].includes(v)
},
binaryStateSort: Boolean,
noDataLabel: String,
noResultsLabel: String,
loadingLabel: String,
selectedRowsLabel: Function,
rowsPerPageLabel: String,
paginationLabel: Function,
tableStyle: {
type: [String, Array, Object],
default: ''
},
tableClass: {
type: [String, Array, Object],
default: ''
}
},
computed: {
computedData () {
let rows = this.data.slice().map((row, i) => {
row.__index = i
return row
})
if (rows.length === 0) {
return {
rowsNumber: 0,
rows: []
}
}
if (this.isServerSide) {
return { rows }
}
const { sortBy, descending, rowsPerPage } = this.computedPagination
if (this.filter) {
rows = this.filterMethod(rows, this.filter, this.computedCols, this.getCellValue)
}
if (this.columnToSort) {
rows = this.sortMethod(rows, sortBy, descending)
}
const rowsNumber = rows.length
if (rowsPerPage) {
rows = rows.slice(this.firstRowIndex, this.lastRowIndex)
}
return { rowsNumber, rows }
},
computedRows () {
return this.computedData.rows
},
computedRowsNumber () {
return this.isServerSide
? this.computedPagination.rowsNumber || 0
: this.computedData.rowsNumber
},
nothingToDisplay () {
return this.computedRows.length === 0
},
isServerSide () {
return this.computedPagination.rowsNumber !== void 0
}
},
render (h) {
return h('div',
{
'class': {
'q-table-grid': this.grid,
'q-table-container': true,
'q-table-dark': this.dark,
'q-table-dense': this.dense,
fullscreen: this.inFullscreen,
scroll: this.inFullscreen
}
},
[
this.getTop(h),
this.getBody(h),
this.getBottom(h)
]
)
},
methods: {
requestServerInteraction (prop) {
this.$nextTick(() => {
this.$emit('request', {
pagination: prop.pagination || this.computedPagination,
filter: prop.filter || this.filter,
getCellValue: this.getCellValue
})
})
},
getBody (h) {
const hasHeader = !this.hideHeader
if (this.grid) {
const item = this.$scopedSlots.item
if (item !== void 0) {
return [
(hasHeader && h('div', { staticClass: 'q-table-middle scroll' }, [
h('table', { staticClass: `q-table${this.dark ? ' q-table-dark' : ''}` }, [
this.getTableHeader(h)
])
])) || null,
h('div', { staticClass: 'row' }, this.computedRows.map(row => {
const
key = row[this.rowKey],
selected = this.isRowSelected(key)
return item(this.addBodyRowMeta({
key,
row,
cols: this.computedCols,
colsMap: this.computedColsMap,
__trClass: selected ? 'selected' : ''
}))
}))
]
}
}
return h('div', { staticClass: 'q-table-middle scroll', 'class': this.tableClass, style: this.tableStyle }, [
h('table', { staticClass: `q-table q-table-${this.separator}-separator${this.dark ? ' q-table-dark' : ''}` },
[
(hasHeader && this.getTableHeader(h)) || null,
this.getTableBody(h)
]
)
])
}
}
}