-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathau-data-table.js
70 lines (68 loc) · 2.17 KB
/
au-data-table.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
/* eslint-disable ember/no-classic-classes, ember/no-classic-components, ember/no-observers, ember/require-tagless-components */
import { typeOf } from '@ember/utils';
import { computed, observer } from '@ember/object';
import { bool, equal, oneWay } from '@ember/object/computed';
import Component from '@ember/component';
import { A } from '@ember/array';
// Source: https://github.com/mu-semtech/ember-data-table/blob/c690a3948b2d9d5f91d69f0a935c6b5cdb4862ca/addon/components/data-table.js
const DataTable = Component.extend({
init() {
this._super(...arguments);
if (this.selection === undefined) this.set('selection', A());
},
noDataMessage: 'No data',
isLoading: false,
lineNumbers: false,
searchDebounceTime: 2000,
enableLineNumbers: bool('lineNumbers'),
enableSelection: oneWay('hasMenu'),
selectionIsEmpty: equal('selection.length', 0),
enableSizes: true,
size: 5,
sizeOptions: computed('size', 'sizes', 'enableSizes', function () {
if (!this.enableSizes) {
return null;
} else {
const sizeOptions = this.sizes || [5, 10, 25, 50, 100];
if (!sizeOptions.includes(this.size)) {
sizeOptions.push(this.size);
}
sizeOptions.sort((a, b) => a - b);
return sizeOptions;
}
}),
hasMenu: false, // set from inner component, migth fail with nested if
enableSearch: computed('filter', function () {
return this.filter || this.filter === '';
}),
autoSearch: true,
filterChanged: observer('filter', function () {
this.set('page', 0);
}),
sizeChanged: observer('size', function () {
this.set('page', 0);
}),
parsedFields: computed('fields', function () {
const fields = this.fields;
if (typeOf(fields) === 'string') {
return fields.split(' ');
} else {
return fields || [];
}
}),
addItemToSelection(item) {
this.selection.addObject(item);
},
removeItemFromSelection(item) {
this.selection.removeObject(item);
},
clearSelection() {
this.selection.clear();
},
});
export default DataTable.extend({
tagName: '',
showPagination: computed('content', 'hidePagination', function () {
return Boolean(this.content) && !this.hidePagination;
}),
});