-
Notifications
You must be signed in to change notification settings - Fork 7
/
BBjGridExWidget.js
237 lines (185 loc) · 5.84 KB
/
BBjGridExWidget.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
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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
/*
* This file is part of the grid project
* (c) Basis Europe <eu@basis.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
bbj_grid_supported_value_formatter = {
'date': bbj_grid_widget_get_value_formatter_date,
'number': bbj_grid_widget_get_value_formatter_number
}
function bbj_grid_widget_post_event(ev) {
window.basisDispatchCustomEvent(ev, ev.payload);
}
function bbj_grid_widget_send_event(payload) {
var d = $doc.getElementById('eventTransporterDiv');
var event = new Event('click');
event.payload = payload;
d.dispatchEvent(event);
}
function bbj_grid_widget_cell_render(params) {
var cdef = params.column.colDef.cellStyleDefaults || {};
var meta = {};
if (params.data.meta)
meta = params.data.meta[params.column.colId] || {};
var colStyle = {};
if (meta["FGCOLOR"])
colStyle.color = meta["FGCOLOR"];
else
if (cdef["FGCOLOR"])
colStyle["color"] = cdef["FGCOLOR"];
if (meta["BGCOLOR"])
colStyle["background-color"] = meta["BGCOLOR"];
else
if (cdef["BGCOLOR"])
colStyle["background-color"] = cdef["BGCOLOR"];
if (meta["ALIGN"])
colStyle["text-align"] = meta["ALIGN"];
else
if (cdef["ALIGN"])
colStyle["text-align"] = cdef["ALIGN"];
if (colStyle.color || colStyle["background-color"] || colStyle["text-align"]) {
return colStyle;
}
else {
return null;
}
};
function bbj_grid_widget_init(container, license, data, options) {
if (agGrid.LisenseManager) {
agGrid.LicenseManager.setLicenseKey(license);
}
options = Object.assign(options || {}, {
rowData: data,
getDocument: function () {
return $doc;
},
onRowDoubleClicked: function (e) {
bbj_grid_widget_send_event({
'type': 'grid-row-doubleclick',
'rows': e.data,
'nodes': e.rowIndex
});
},
onSelectionChanged: function (e) {
var r = e.api.getSelectedRows();
var nodes = e.api.getSelectedNodes();
var n = [];
for (var i in nodes) {
var node_i = nodes[i];
n.push(node_i.id);
}
bbj_grid_widget_send_event({
'type': 'grid-select-row',
'rows': r,
'nodes': n
});
},
getNodeChildDetails: function (rowItem) {
if (rowItem.__node__children) {
return {
group: true,
expanded: false,
// provide ag-Grid with the children of this group
children: rowItem.__node__children,
// the key is used by the default group cellRenderer
key: rowItem.__node__name
};
} else {
return null;
}
}
});
for (var i in options.columnDefs) {
options.columnDefs[i].cellStyle = bbj_grid_widget_cell_render;
options.columnDefs[i].valueFormatter = bbj_grid_widget_get_value_formatter(
options.columnDefs[i].filter
);
}
return new agGrid.Grid(container, options);
}
function bbj_grid_widget_fit_grid(fitmode) {
$doc.bbj_grid_widget.api.sizeColumnsToFit();
}
function bbj_grid_widget_set_selected_rows(rows) {
$doc.bbj_grid_widget.api.forEachNodeAfterFilterAndSort(function (node) {
if (rows.indexOf(node.rowIndex) > -1) {
node.setSelected(true);
node.expanded = true;
}
}.bind(this));
$doc.bbj_grid_widget.api.onGroupExpandedOrCollapsed()
}
function bbj_grid_widget_set_select_all(filtered) {
if (1 === filtered) {
$doc.bbj_grid_widget.api.selectAllFiltered();
} else {
$doc.bbj_grid_widget.api.selectAll();
}
}
function bbj_grid_widget_set_deselect_all(filtered) {
if (1 === filtered) {
$doc.bbj_grid_widget.api.deselectAllFiltered();
} else {
$doc.bbj_grid_widget.api.deselectAll();
}
}
function bbj_grid_widget_set_expand_all() {
$doc.bbj_grid_widget.api.expandAll();
}
function bbj_grid_widget_set_collapse_all() {
$doc.bbj_grid_widget.api.collapseAll();
}
function bbj_grid_widget_set_visible_row(index, position) {
$doc.bbj_grid_widget.api.ensureIndexVisible(index, position);
}
function bbj_grid_widget_set_visible_column(columnId) {
$doc.bbj_grid_widget.api.ensureColumnVisible(columnId);
}
function bbj_grid_widget_set_column_width(columnid, width) {
$doc.bbj_grid_widget.columnApi.setColumnWidth(columnid, width);
}
function bbj_grid_widget_set_column_pin(columnid,pin) {
$doc.bbj_grid_widget.columnApi.setColumnPinned(columnid, pin);
}
function bbj_grid_widget_get_state() {
var state = $doc.bbj_grid_widget.columnApi.getColumnState();
return JSON.stringify(state);
}
function bbj_grid_widget_set_state(state) {
$doc.bbj_grid_widget.columnApi.setColumnState(state);
}
function bbj_grid_widget_get_value_formatter(filter) {
return bbj_grid_supported_value_formatter && bbj_grid_supported_value_formatter.hasOwnProperty(filter) ?
bbj_grid_supported_value_formatter[filter] : null;
}
function bbj_grid_widget_get_value_formatter_date(data) {
if (
($doc.bbj_grid_widget_meta && $doc.bbj_grid_widget_meta.hasOwnProperty(data.colDef.field)) &&
$doc.bbj_grid_widget_meta[data.colDef.field].hasOwnProperty('MASK')
) {
return bbj_mask_date(
data.value,
$doc.bbj_grid_widget_meta[data.colDef.field].MASK //'%Y-%Mz-%Dz'
);
} else return data.value;
}
function bbj_grid_widget_get_value_formatter_number(data) {
if (
($doc.bbj_grid_widget_meta && $doc.bbj_grid_widget_meta.hasOwnProperty(data.colDef.field)) &&
$doc.bbj_grid_widget_meta[data.colDef.field].hasOwnProperty('MASK')
) {
return bbj_mask_number(
data.value,
$doc.bbj_grid_widget_meta[data.colDef.field].MASK
);
} else return data.value;
}
function bbj_grid_widget_set_data(json, options) {
var container = $doc.getElementById('grid');
container.innerHTML = '';
$doc.bbj_grid_widget_meta = json[0].meta;
$doc.bbj_grid_widget = options;
$doc.bbj_grid_widget_instance = bbj_grid_widget_init(container, '', json, options);
}