-
-
Notifications
You must be signed in to change notification settings - Fork 19
/
example9.ts
142 lines (134 loc) · 4.94 KB
/
example9.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
import { autoinject, bindable } from 'aurelia-framework';
import { Column, FieldType, FilterService, Formatter, Formatters, FormElementType, GridOption } from 'aurelia-slickgrid';
@autoinject()
export class Example9 {
@bindable() gridObj: any;
@bindable() dataviewObj: any;
title = 'Example 9: Grid Menu Control';
subTitle = `
This example demonstrates using the <b>Slick.Controls.GridMenu</b> plugin to easily add a Grid Menu (aka hamburger menu) on the top right corner of the grid.<br/>
<ul>
<li>The Grid Menu uses the following icon by default "fa-bars" <span class="fa fa-bars"></span> (which looks like a hamburger, hence the name)</li>
<ul><li>Another icon which you could use is "fa-ellipsis-v" <span class="fa fa-ellipsis-v"></span> (which is shown in this example)</li></ul>
<li>By default the Grid Menu shows all columns which you can show/hide</li>
<li>You can configure multiple "commands" to show up in the Grid Menu and use the "onGridMenuCommand()" callback</li>
<li>Doing a "right+click" over any column header will also provide a way to show/hide a column (via the Column Picker Plugin)</li>
</ul>
`;
columnDefinitions: Column[];
gridOptions: GridOption;
dataset = [];
visibleColumns;
constructor(private filterService: FilterService) {
// define the grid options & columns and then create the grid itself
this.defineGrid();
}
attached() {
// populate the dataset once the grid is ready
this.getData();
}
defineGrid() {
this.columnDefinitions = [
{ id: 'title', name: 'Title', field: 'title', filterable: true, type: FieldType.string },
{ id: 'duration', name: 'Duration', field: 'duration', sortable: true, filterable: true, type: FieldType.string },
{ id: '%', name: '% Complete', field: 'percentComplete', sortable: true, filterable: true, type: FieldType.number },
{ id: 'start', name: 'Start', field: 'start', filterable: true, type: FieldType.string },
{ id: 'finish', name: 'Finish', field: 'finish', filterable: true, type: FieldType.string },
{
id: 'effort-driven', name: 'Effort Driven', field: 'effortDriven', maxWidth: 80, formatter: Formatters.checkmark,
type: FieldType.boolean,
minWidth: 100,
sortable: true,
filterable: true,
filter: {
searchTerm: '', // default selection
type: FormElementType.select,
selectOptions: [{ value: '', label: '' }, { value: true, label: 'true' }, { value: false, label: 'false' }]
}
}
];
this.gridOptions = {
enableAutoResize: true,
enableHeaderMenu: true,
enableGridMenu: true,
autoResize: {
containerId: 'demo-container',
sidePadding: 15
},
enableFiltering: true,
enableCellNavigation: true,
gridMenu: {
customTitle: 'Commands',
columnTitle: 'Columns',
iconCssClass: 'fa fa-ellipsis-v',
menuWidth: 17,
resizeOnShowHeaderRow: true,
customItems: [
{
iconCssClass: 'fa fa-filter text-danger',
title: 'Clear All Filters',
disabled: false,
command: 'clear-filter'
},
{
iconCssClass: 'fa fa-random',
title: 'Toggle Filter Row',
disabled: false,
command: 'toggle-filter'
},
{
iconCssClass: 'fa fa-random',
title: 'Toggle Top Panel',
disabled: false,
command: 'toggle-toppanel'
},
{
iconCssClass: 'fa fa-question-circle',
title: 'Help',
disabled: false,
command: 'help'
},
{
title: 'Disabled command',
disabled: true,
command: 'disabled-command'
}
]
},
onGridMenuCommand: (e, args) => {
if (args.command === 'toggle-filter') {
this.gridObj.setHeaderRowVisibility(!this.gridObj.getOptions().showHeaderRow);
} else if (args.command === 'toggle-toppanel') {
this.gridObj.setTopPanelVisibility(!this.gridObj.getOptions().showTopPanel);
} else if (args.command === 'clear-filter') {
this.filterService.clearFilters();
this.dataviewObj.refresh();
} else {
alert('Command: ' + args.command);
}
}
};
}
getData() {
// Set up some test columns.
const mockDataset = [];
for (let i = 0; i < 500; i++) {
mockDataset[i] = {
id: i,
title: 'Task ' + i,
duration: Math.round(Math.random() * 25) + ' days',
percentComplete: Math.round(Math.random() * 100),
start: '01/01/2009',
finish: '01/05/2009',
effortDriven: (i % 5 === 0)
};
}
this.dataset = mockDataset;
}
gridObjChanged(grid) {
this.gridObj = grid;
}
dataviewChanged(dataview) {
this.dataviewObj = dataview;
}
}