-
-
Notifications
You must be signed in to change notification settings - Fork 18
/
example21.ts
164 lines (145 loc) · 4.63 KB
/
example21.ts
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
import { bindable } from 'aurelia';
import {
AureliaGridInstance,
Column,
FieldType,
Formatters,
GridOption,
OperatorString,
} from 'aurelia-slickgrid';
import './example21.scss';
export class Example21 {
@bindable() selectedColumn!: Column;
@bindable() selectedOperator!: string;
@bindable() searchValue = '';
title = 'Example 21: Grid AutoHeight';
subTitle = `
The SlickGrid option "autoHeight" can be used if you wish to keep the full height of the grid without any scrolling
<ul>
<li>You define a fixed grid width via "gridWidth" in the View</li>
<li>You can still use the "autoResize" for the width to be resized automatically (the height will never change in this case)</li>
<li>This dataset has 25 rows, if you scroll down the page you can see the entire set is shown without any grid scrolling (though you might have browser scrolling)</li>
</ul>
`;
aureliaGrid!: AureliaGridInstance;
columnDefinitions: Column[] = [];
gridOptions!: GridOption;
dataset: any[] = [];
operatorList: OperatorString[] = ['=', '<', '<=', '>', '>=', '<>', 'StartsWith', 'EndsWith'];
constructor() {
// define the grid options & columns and then create the grid itself
this.defineGrid();
}
attached() {
// populate the dataset once the grid is ready
this.getData();
}
/* Define grid Options and Columns */
defineGrid() {
this.columnDefinitions = [
{
id: 'title', name: 'Title', field: 'title',
width: 100, sortable: true,
type: FieldType.string
},
{
id: 'duration', name: 'Duration (days)', field: 'duration',
width: 100, sortable: true,
type: FieldType.number
},
{
id: 'complete', name: '% Complete', field: 'percentComplete',
width: 100, sortable: true,
formatter: Formatters.percentCompleteBar,
type: FieldType.number
},
{
id: 'start', name: 'Start', field: 'start',
width: 100, sortable: true,
formatter: Formatters.dateIso,
type: FieldType.date
},
{
id: 'finish', name: 'Finish', field: 'finish',
width: 100, sortable: true,
formatter: Formatters.dateIso,
type: FieldType.date
},
{
id: 'effort-driven', name: 'Effort Driven', field: 'effortDriven',
width: 100, sortable: true,
formatter: Formatters.checkmarkMaterial,
type: FieldType.number
}
];
this.gridOptions = {
// if you want to disable autoResize and use a fixed width which requires horizontal scrolling
// it's advised to disable the autoFitColumnsOnFirstLoad as well
// enableAutoResize: false,
// autoFitColumnsOnFirstLoad: false,
autoHeight: true,
autoResize: {
container: '#demo-container',
rightPadding: 10
},
// enable the filtering but hide the user filter row since we use our own single filter
enableFiltering: true,
showHeaderRow: false, // hide the filter row (header row)
alwaysShowVerticalScroll: false,
enableColumnPicker: true,
enableCellNavigation: true,
enableRowSelection: true
};
}
getData() {
// mock a dataset
const mockedDataset: any[] = [];
for (let i = 0; i < 25; i++) {
const randomYear = 2000 + Math.floor(Math.random() * 10);
const randomMonth = Math.floor(Math.random() * 11);
const randomDay = Math.floor((Math.random() * 29));
const randomPercent = Math.round(Math.random() * 100);
mockedDataset[i] = {
id: i,
title: 'Task ' + i,
duration: Math.round(Math.random() * 100) + '',
percentComplete: randomPercent,
percentCompleteNumber: randomPercent,
start: new Date(randomYear, randomMonth, randomDay),
finish: new Date(randomYear, (randomMonth + 1), randomDay),
effortDriven: (i % 5 === 0)
};
}
this.dataset = mockedDataset;
}
generatePhoneNumber() {
let phone = '';
for (let i = 0; i < 10; i++) {
phone += Math.round(Math.random() * 9) + '';
}
return phone;
}
//
// -- if any of the Search form input changes, we'll call the updateFilter() method
//
clearGridSearchInput() {
this.searchValue = '';
this.updateFilter();
}
selectedOperatorChanged() {
this.updateFilter();
}
selectedColumnChanged() {
this.updateFilter();
}
searchValueChanged() {
this.updateFilter();
}
updateFilter() {
this.aureliaGrid?.filterService.updateSingleFilter({
columnId: `${this.selectedColumn.id || ''}`,
operator: this.selectedOperator as OperatorString,
searchTerms: [this.searchValue || '']
});
}
}