x4js 1.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/application.d.ts +95 -0
- package/lib/application.js +137 -0
- package/lib/base64.d.ts +31 -0
- package/lib/base64.js +135 -0
- package/lib/base_component.d.ts +64 -0
- package/lib/base_component.js +77 -0
- package/lib/button.d.ts +145 -0
- package/lib/button.js +235 -0
- package/lib/calendar.d.ts +77 -0
- package/lib/calendar.js +236 -0
- package/lib/canvas.d.ts +88 -0
- package/lib/canvas.js +354 -0
- package/lib/cardview.d.ts +83 -0
- package/lib/cardview.js +152 -0
- package/lib/checkbox.d.ts +72 -0
- package/lib/checkbox.js +126 -0
- package/lib/color.d.ts +144 -0
- package/lib/color.js +584 -0
- package/lib/colorpicker.d.ts +98 -0
- package/lib/colorpicker.js +1457 -0
- package/lib/combobox.d.ts +97 -0
- package/lib/combobox.js +246 -0
- package/lib/component.d.ts +572 -0
- package/lib/component.js +1712 -0
- package/lib/datastore.d.ts +392 -0
- package/lib/datastore.js +986 -0
- package/lib/dialog.d.ts +171 -0
- package/lib/dialog.js +468 -0
- package/lib/dom_events.d.ts +284 -0
- package/lib/dom_events.js +13 -0
- package/lib/drag_manager.d.ts +26 -0
- package/lib/drag_manager.js +118 -0
- package/lib/drawtext.d.ts +43 -0
- package/lib/drawtext.js +261 -0
- package/lib/fileupload.d.ts +60 -0
- package/lib/fileupload.js +158 -0
- package/lib/form.d.ts +122 -0
- package/lib/form.js +293 -0
- package/lib/formatters.d.ts +31 -0
- package/lib/formatters.js +75 -0
- package/lib/gridview.d.ts +171 -0
- package/lib/gridview.js +786 -0
- package/lib/hosts/host.d.ts +44 -0
- package/lib/hosts/host.js +69 -0
- package/lib/i18n.d.ts +67 -0
- package/lib/i18n.js +169 -0
- package/lib/icon.d.ts +56 -0
- package/lib/icon.js +173 -0
- package/lib/image.d.ts +51 -0
- package/lib/image.js +149 -0
- package/lib/index.js +1 -0
- package/lib/input.d.ts +86 -0
- package/lib/input.js +172 -0
- package/lib/label.d.ts +54 -0
- package/lib/label.js +86 -0
- package/lib/layout.d.ts +77 -0
- package/lib/layout.js +261 -0
- package/lib/link.d.ts +46 -0
- package/lib/link.js +55 -0
- package/lib/listview.d.ts +173 -0
- package/lib/listview.js +532 -0
- package/lib/md5.d.ts +56 -0
- package/lib/md5.js +397 -0
- package/lib/menu.d.ts +122 -0
- package/lib/menu.js +276 -0
- package/lib/messagebox.d.ts +64 -0
- package/lib/messagebox.js +141 -0
- package/lib/panel.d.ts +42 -0
- package/lib/panel.js +61 -0
- package/lib/popup.d.ts +71 -0
- package/lib/popup.js +373 -0
- package/lib/property_editor.d.ts +67 -0
- package/lib/property_editor.js +247 -0
- package/lib/radiobtn.d.ts +68 -0
- package/lib/radiobtn.js +131 -0
- package/lib/rating.d.ts +49 -0
- package/lib/rating.js +93 -0
- package/lib/request.d.ts +48 -0
- package/lib/request.js +220 -0
- package/lib/router.d.ts +13 -0
- package/lib/router.js +27 -0
- package/lib/settings.d.ts +33 -0
- package/lib/settings.js +63 -0
- package/lib/sidebarview.d.ts +44 -0
- package/lib/sidebarview.js +73 -0
- package/lib/smartedit.d.ts +103 -0
- package/lib/smartedit.js +381 -0
- package/lib/spreadsheet.d.ts +214 -0
- package/lib/spreadsheet.js +1073 -0
- package/lib/styles.d.ts +81 -0
- package/lib/styles.js +262 -0
- package/lib/svgcomponent.d.ts +165 -0
- package/lib/svgcomponent.js +350 -0
- package/lib/tabbar.d.ts +41 -0
- package/lib/tabbar.js +66 -0
- package/lib/tabview.d.ts +45 -0
- package/lib/tabview.js +79 -0
- package/lib/textarea.d.ts +59 -0
- package/lib/textarea.js +119 -0
- package/lib/textedit.d.ts +118 -0
- package/lib/textedit.js +406 -0
- package/lib/texthiliter.d.ts +56 -0
- package/lib/texthiliter.js +219 -0
- package/lib/toaster.d.ts +38 -0
- package/lib/toaster.js +58 -0
- package/lib/tools.d.ts +382 -0
- package/lib/tools.js +1096 -0
- package/lib/tooltips.d.ts +42 -0
- package/lib/tooltips.js +148 -0
- package/lib/treeview.d.ts +128 -0
- package/lib/treeview.js +490 -0
- package/lib/x4_events.d.ts +253 -0
- package/lib/x4_events.js +363 -0
- package/package.json +21 -0
- package/src/README.md +2 -0
- package/src/application.ts +191 -0
- package/src/base64.ts +162 -0
- package/src/base_component.ts +118 -0
- package/src/button.ts +327 -0
- package/src/calendar.ts +312 -0
- package/src/canvas.ts +501 -0
- package/src/cardview.ts +220 -0
- package/src/checkbox.ts +178 -0
- package/src/color.ts +748 -0
- package/src/colorpicker.ts +1618 -0
- package/src/combobox.ts +348 -0
- package/src/component.ts +2330 -0
- package/src/datastore.ts +1318 -0
- package/src/dialog.ts +631 -0
- package/src/dom_events.ts +297 -0
- package/src/drag_manager.ts +168 -0
- package/src/drawtext.ts +342 -0
- package/src/fileupload.ts +208 -0
- package/src/form.ts +362 -0
- package/src/formatters.ts +96 -0
- package/src/gridview.ts +1051 -0
- package/src/hosts/electron.ts +161 -0
- package/src/hosts/host.ts +100 -0
- package/src/hosts/nwjs.ts +141 -0
- package/src/hosts/nwjs_types.ts +339 -0
- package/src/i18n.ts +205 -0
- package/src/icon.ts +237 -0
- package/src/image.ts +198 -0
- package/src/input.ts +236 -0
- package/src/label.ts +124 -0
- package/src/layout.ts +366 -0
- package/src/link.ts +82 -0
- package/src/listview.ts +749 -0
- package/src/md5.ts +432 -0
- package/src/menu.ts +394 -0
- package/src/messagebox.ts +199 -0
- package/src/panel.ts +81 -0
- package/src/popup.ts +488 -0
- package/src/property_editor.ts +333 -0
- package/src/radiobtn.ts +190 -0
- package/src/rating.ts +131 -0
- package/src/request.ts +296 -0
- package/src/router.ts +43 -0
- package/src/settings.ts +75 -0
- package/src/sidebarview.ts +97 -0
- package/src/smartedit.ts +532 -0
- package/src/spreadsheet.ts +1423 -0
- package/src/styles.ts +332 -0
- package/src/svgcomponent.ts +440 -0
- package/src/tabbar.ts +105 -0
- package/src/tabview.ts +106 -0
- package/src/textarea.ts +183 -0
- package/src/textedit.ts +535 -0
- package/src/texthiliter.ts +284 -0
- package/src/toaster.ts +76 -0
- package/src/tools.ts +1391 -0
- package/src/tooltips.ts +185 -0
- package/src/treeview.ts +670 -0
- package/src/x4.less +1940 -0
- package/src/x4_events.ts +558 -0
- package/tsconfig.json +14 -0
package/src/gridview.ts
ADDED
|
@@ -0,0 +1,1051 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ___ ___ __
|
|
3
|
+
* \ \/ / / _
|
|
4
|
+
* \ / /_| |_
|
|
5
|
+
* / \____ _|
|
|
6
|
+
* /__/\__\ |_|
|
|
7
|
+
*
|
|
8
|
+
* @file gridview.ts
|
|
9
|
+
* @author Etienne Cochard
|
|
10
|
+
* @license
|
|
11
|
+
* Copyright (c) 2019-2021 R-libre ingenierie
|
|
12
|
+
*
|
|
13
|
+
* This program is free software; you can redistribute it and/or modify
|
|
14
|
+
* it under the terms of the GNU General Public License as published by
|
|
15
|
+
* the Free Software Foundation; either version 3 of the License, or
|
|
16
|
+
* (at your option) any later version.
|
|
17
|
+
*
|
|
18
|
+
* This program is distributed in the hope that it will be useful,
|
|
19
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
20
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
21
|
+
* GNU General Public License for more details.
|
|
22
|
+
*
|
|
23
|
+
* You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
24
|
+
**/
|
|
25
|
+
|
|
26
|
+
const T_UPDATE = Symbol('update');
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* todo: sizable column
|
|
30
|
+
* todo: button in a column
|
|
31
|
+
*/
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
import { HLayout, VLayout } from './layout'
|
|
35
|
+
import { Component, ContainerEventMap, EvSize, EvDblClick, CProps, flyWrap, html, HtmlString, SizerOverlay } from './component'
|
|
36
|
+
import { Label } from './label'
|
|
37
|
+
import { _tr } from './i18n'
|
|
38
|
+
import * as Formatters from './formatters'
|
|
39
|
+
import { downloadData } from './tools'
|
|
40
|
+
import { DataView, DataStore, Record } from './datastore'
|
|
41
|
+
|
|
42
|
+
import { EvContextMenu, EvSelectionChange, BasicEvent, EventDisposer } from "./x4_events";
|
|
43
|
+
|
|
44
|
+
export interface EvGridCheck extends BasicEvent {
|
|
45
|
+
rec: Record;
|
|
46
|
+
chk: boolean;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export function EvGridCheck(rec: Record, chk: boolean) {
|
|
50
|
+
return BasicEvent<EvGridCheck>( { rec, chk } );
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
*
|
|
59
|
+
*/
|
|
60
|
+
|
|
61
|
+
export interface GridColumn {
|
|
62
|
+
id: any;
|
|
63
|
+
title: string;
|
|
64
|
+
width: number;
|
|
65
|
+
flex?: number;
|
|
66
|
+
align?: 'left' | 'center' | 'right';
|
|
67
|
+
renderer?: CellRenderer;
|
|
68
|
+
formatter?: Formatters.FormatFunc;
|
|
69
|
+
cls?: string;
|
|
70
|
+
sortable?: boolean;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export type CellRenderer = (rec: Record) => Component;
|
|
74
|
+
export type RowClassifier = (rec: Record, Row: Component) => void;
|
|
75
|
+
export type ContextMenuGridItem = (event: MouseEvent, item: Record, grid: GridView) => any;
|
|
76
|
+
|
|
77
|
+
type emptyFn = () => string;
|
|
78
|
+
|
|
79
|
+
interface GridViewEventMap extends ContainerEventMap {
|
|
80
|
+
dblClick?: EvDblClick;
|
|
81
|
+
selectionChange?: EvSelectionChange;
|
|
82
|
+
contextMenu?: EvContextMenu;
|
|
83
|
+
gridCheck?: EvGridCheck;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export interface GridViewProps extends CProps<GridViewEventMap> {
|
|
87
|
+
store: DataStore | DataView;
|
|
88
|
+
columns: GridColumn[];
|
|
89
|
+
calcRowClass?: RowClassifier;
|
|
90
|
+
empty_text?: string | emptyFn; // set or return '' to avoid message
|
|
91
|
+
hasMarks?: boolean; // if true add a checkbox on left side cf. clearMarks, getMarksIds
|
|
92
|
+
hasFooter?: boolean;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* gridview class
|
|
98
|
+
*/
|
|
99
|
+
|
|
100
|
+
export class GridView extends VLayout<GridViewProps, GridViewEventMap> {
|
|
101
|
+
|
|
102
|
+
protected m_dataview: DataView;
|
|
103
|
+
protected m_data_cx: EventDisposer;
|
|
104
|
+
|
|
105
|
+
protected m_columns: GridColumn[];
|
|
106
|
+
|
|
107
|
+
protected m_view_el: Component;
|
|
108
|
+
protected m_container: Component;
|
|
109
|
+
protected m_header: Component;
|
|
110
|
+
|
|
111
|
+
protected m_footer: Component;
|
|
112
|
+
|
|
113
|
+
protected m_empty_msg: Label;
|
|
114
|
+
protected m_empty_text: string | emptyFn;
|
|
115
|
+
|
|
116
|
+
protected m_selection: any;
|
|
117
|
+
private m_itemHeight: number;
|
|
118
|
+
private m_topIndex: number;
|
|
119
|
+
protected m_visible_rows: Component[]; // shown elements
|
|
120
|
+
|
|
121
|
+
protected m_hasMarks: boolean;
|
|
122
|
+
protected m_marks: Set<any>; // checked elements
|
|
123
|
+
|
|
124
|
+
private m_recycler: Component[];
|
|
125
|
+
|
|
126
|
+
private m_rowClassifier: RowClassifier;
|
|
127
|
+
|
|
128
|
+
constructor(props: GridViewProps) {
|
|
129
|
+
super(props);
|
|
130
|
+
|
|
131
|
+
this.m_columns = props.columns;
|
|
132
|
+
this.m_hasMarks = props.hasMarks ?? false;
|
|
133
|
+
this.m_marks = new Set<any>();
|
|
134
|
+
|
|
135
|
+
// prepend the checkable column
|
|
136
|
+
if (this.m_hasMarks) {
|
|
137
|
+
this.m_columns.unshift({
|
|
138
|
+
id: 'id',
|
|
139
|
+
title: '',
|
|
140
|
+
width: 30,
|
|
141
|
+
renderer: (e) => this._renderCheck( e )
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
this.setAttribute('tabindex', 0);
|
|
146
|
+
|
|
147
|
+
this.m_topIndex = 0;
|
|
148
|
+
this.m_itemHeight = 0;
|
|
149
|
+
this.m_recycler = [];
|
|
150
|
+
this.m_rowClassifier = props.calcRowClass;
|
|
151
|
+
|
|
152
|
+
this.m_empty_text = props.empty_text ?? _tr.global.empty_list;
|
|
153
|
+
|
|
154
|
+
//this.setDomEvent('create', this._handleCreate, this);
|
|
155
|
+
this.setDomEvent('click', (e)=>this._itemClick(e));
|
|
156
|
+
this.setDomEvent('dblclick', (e)=>this._itemDblClick(e));
|
|
157
|
+
this.setDomEvent('contextmenu', (e)=>this._itemMenu(e));
|
|
158
|
+
this.setDomEvent('keydown', (e)=>this._handleKey(e));
|
|
159
|
+
|
|
160
|
+
this.setStore(props.store);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
componentCreated() {
|
|
164
|
+
this._updateScroll(true);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
*
|
|
169
|
+
*/
|
|
170
|
+
|
|
171
|
+
private _moveSel(sens: number, select = true) {
|
|
172
|
+
|
|
173
|
+
let sel = this.m_selection;
|
|
174
|
+
let scrolltype = null;
|
|
175
|
+
|
|
176
|
+
if (sel === undefined) {
|
|
177
|
+
sel = this.m_dataview.getByIndex(0).getID();
|
|
178
|
+
}
|
|
179
|
+
else {
|
|
180
|
+
|
|
181
|
+
let index = this.m_dataview.indexOfId(this.m_selection);
|
|
182
|
+
|
|
183
|
+
if (sens == 1) {
|
|
184
|
+
index++;
|
|
185
|
+
}
|
|
186
|
+
else if (sens == -1) {
|
|
187
|
+
index--;
|
|
188
|
+
}
|
|
189
|
+
else if (sens == 2) {
|
|
190
|
+
index += this.m_visible_rows.length - 1;
|
|
191
|
+
}
|
|
192
|
+
else if (sens == -2) {
|
|
193
|
+
index -= this.m_visible_rows.length - 1;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
if (sens < 0) {
|
|
197
|
+
scrolltype = 'start';
|
|
198
|
+
}
|
|
199
|
+
else {
|
|
200
|
+
scrolltype = 'end';
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
if (index < 0) {
|
|
204
|
+
index = 0;
|
|
205
|
+
}
|
|
206
|
+
else if (index >= this.m_dataview.count) {
|
|
207
|
+
index = this.m_dataview.count - 1;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
sel = this.m_dataview.getByIndex(index).getID();
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
if (this.m_selection != sel && select) {
|
|
214
|
+
this._selectItem(sel, null, scrolltype);
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
return sel;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/**
|
|
221
|
+
*
|
|
222
|
+
*/
|
|
223
|
+
|
|
224
|
+
private _handleKey(event: KeyboardEvent) {
|
|
225
|
+
//debugger;
|
|
226
|
+
|
|
227
|
+
if (!this.m_dataview || this.m_dataview.count == 0) {
|
|
228
|
+
return;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
switch (event.key) {
|
|
232
|
+
case 'ArrowDown':
|
|
233
|
+
case 'Down': {
|
|
234
|
+
this._moveSel(1);
|
|
235
|
+
break;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
case 'ArrowUp':
|
|
239
|
+
case 'Up': {
|
|
240
|
+
this._moveSel(-1);
|
|
241
|
+
break;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
case 'PageUp': {
|
|
245
|
+
this._moveSel(-2);
|
|
246
|
+
break;
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
case 'PageDown': {
|
|
250
|
+
this._moveSel(2);
|
|
251
|
+
break;
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
/**
|
|
257
|
+
*
|
|
258
|
+
*/
|
|
259
|
+
|
|
260
|
+
getNextSel(sens: number) {
|
|
261
|
+
return this._moveSel(sens, false);
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
private _scrollIntoView(id: any, sens?: string) {
|
|
265
|
+
|
|
266
|
+
let itm = this._findItem(id);
|
|
267
|
+
if (itm) {
|
|
268
|
+
itm.scrollIntoView({
|
|
269
|
+
block: 'center' //<ScrollLogicalPosition>sens ?? 'nearest'
|
|
270
|
+
});
|
|
271
|
+
}
|
|
272
|
+
else {
|
|
273
|
+
this.m_topIndex = this.m_dataview.indexOfId(id);
|
|
274
|
+
this.m_view_el.dom.scrollTop = this.m_topIndex * this.m_itemHeight;
|
|
275
|
+
this._buildItems();
|
|
276
|
+
|
|
277
|
+
this._scrollIntoView(id);
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
/**
|
|
283
|
+
* change the list of item displayed
|
|
284
|
+
* @param items - new array of items
|
|
285
|
+
*/
|
|
286
|
+
|
|
287
|
+
public setStore(store: DataStore | DataView) {
|
|
288
|
+
|
|
289
|
+
this.m_selection = undefined;
|
|
290
|
+
|
|
291
|
+
if (store instanceof DataStore) {
|
|
292
|
+
this.m_dataview = store.createView();
|
|
293
|
+
}
|
|
294
|
+
else {
|
|
295
|
+
this.m_dataview = store;
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
if( this.m_hasMarks ) {
|
|
299
|
+
this.clearMarks( );
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
// unlink previous observer
|
|
303
|
+
if (this.m_data_cx) {
|
|
304
|
+
this.m_data_cx.dispose( );
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
if (this.m_dataview) {
|
|
308
|
+
|
|
309
|
+
this.m_data_cx = this.m_dataview.on( 'view_change', ( ev ) => {
|
|
310
|
+
if (ev.action == 'change') {
|
|
311
|
+
this.m_selection = undefined;
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
this._updateScroll(true);
|
|
315
|
+
});
|
|
316
|
+
|
|
317
|
+
//this.update( );
|
|
318
|
+
this._updateScroll(true);
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
public getView(): DataView {
|
|
323
|
+
return this.m_dataview;
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
/**
|
|
327
|
+
* return the current selection (row id) or null
|
|
328
|
+
*/
|
|
329
|
+
|
|
330
|
+
public getSelection(): any {
|
|
331
|
+
return this.m_selection;
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
public getSelRec(): Record {
|
|
335
|
+
if (this.m_selection) {
|
|
336
|
+
return this.m_dataview.getById(this.m_selection);
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
return null;
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
public setSelection(recId: any) {
|
|
343
|
+
this._selectItem(recId, null, 'center');
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
/** @ignore */
|
|
347
|
+
render() {
|
|
348
|
+
|
|
349
|
+
this.m_recycler = [];
|
|
350
|
+
this.m_container = new Component({
|
|
351
|
+
cls: 'content',
|
|
352
|
+
});
|
|
353
|
+
|
|
354
|
+
this.m_empty_msg = new Label({
|
|
355
|
+
cls: 'empty-msg',
|
|
356
|
+
text: ''
|
|
357
|
+
});
|
|
358
|
+
|
|
359
|
+
this.m_view_el = new Component({
|
|
360
|
+
cls: '@scroll-view',
|
|
361
|
+
flex: 1,
|
|
362
|
+
dom_events: {
|
|
363
|
+
sizechange: ( ) => this._updateScroll(true),
|
|
364
|
+
scroll: ( ) => this._updateScroll(false)
|
|
365
|
+
},
|
|
366
|
+
content: this.m_container
|
|
367
|
+
});
|
|
368
|
+
|
|
369
|
+
let cols = this.m_columns.map((col, index) => {
|
|
370
|
+
|
|
371
|
+
let cls = '@cell';
|
|
372
|
+
if (col.cls) {
|
|
373
|
+
cls += ' ' + col.cls;
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
let comp = new Component({
|
|
377
|
+
cls,
|
|
378
|
+
content: new Component({
|
|
379
|
+
tag: 'span',
|
|
380
|
+
content: col.title
|
|
381
|
+
}),
|
|
382
|
+
flex: col.flex,
|
|
383
|
+
sizable: 'right',
|
|
384
|
+
style: {
|
|
385
|
+
width: col.width
|
|
386
|
+
},
|
|
387
|
+
dom_events: {
|
|
388
|
+
click: (ev: MouseEvent) => {
|
|
389
|
+
let t = flyWrap(<HTMLElement>ev.target);
|
|
390
|
+
if (!t.hasClass('@sizer-overlay')) { // avoid sizer click
|
|
391
|
+
this._sortCol(col);
|
|
392
|
+
ev.preventDefault();
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
});
|
|
397
|
+
|
|
398
|
+
const resizeCol = ( ev: EvSize ) => {
|
|
399
|
+
this._on_col_resize(index, ev.size.width);
|
|
400
|
+
|
|
401
|
+
if( this.m_footer ) {
|
|
402
|
+
let col = Component.getElement( this.m_footer.dom.childNodes[index] as HTMLElement );
|
|
403
|
+
if( col ) {
|
|
404
|
+
col.setStyleValue( 'width', ev.size.width );
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
new SizerOverlay({
|
|
410
|
+
target: comp,
|
|
411
|
+
sens: 'right',
|
|
412
|
+
events: {resize: ( e ) => resizeCol(e )}
|
|
413
|
+
});
|
|
414
|
+
|
|
415
|
+
(<any>col).$col = comp;
|
|
416
|
+
return comp;
|
|
417
|
+
});
|
|
418
|
+
|
|
419
|
+
// compute full width
|
|
420
|
+
let full_width = 0;
|
|
421
|
+
this.m_columns.forEach((col) => {
|
|
422
|
+
full_width += col.width ?? 0;
|
|
423
|
+
});
|
|
424
|
+
|
|
425
|
+
this.m_header = new HLayout({
|
|
426
|
+
cls: '@header',
|
|
427
|
+
content: <any>cols,
|
|
428
|
+
style: {
|
|
429
|
+
minWidth: full_width
|
|
430
|
+
}
|
|
431
|
+
});
|
|
432
|
+
|
|
433
|
+
|
|
434
|
+
if( this.m_props.hasFooter ) {
|
|
435
|
+
let foots = this.m_columns.map((col, index) => {
|
|
436
|
+
|
|
437
|
+
let cls = '@cell';
|
|
438
|
+
|
|
439
|
+
if (col.align) {
|
|
440
|
+
cls += ' ' + col.align;
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
if (col.cls) {
|
|
444
|
+
cls += ' ' + col.cls;
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
let comp = new Component({
|
|
448
|
+
cls,
|
|
449
|
+
data: { col: index },
|
|
450
|
+
flex: col.flex,
|
|
451
|
+
style: {
|
|
452
|
+
width: col.width
|
|
453
|
+
}
|
|
454
|
+
});
|
|
455
|
+
|
|
456
|
+
return comp;
|
|
457
|
+
});
|
|
458
|
+
|
|
459
|
+
this.m_footer = new HLayout({
|
|
460
|
+
cls: '@footer',
|
|
461
|
+
content: <any>foots,
|
|
462
|
+
style: {
|
|
463
|
+
minWidth: full_width
|
|
464
|
+
}
|
|
465
|
+
});
|
|
466
|
+
}
|
|
467
|
+
else {
|
|
468
|
+
this.m_footer = null;
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
this.setContent([
|
|
472
|
+
this.m_header,
|
|
473
|
+
this.m_view_el,
|
|
474
|
+
this.m_footer,
|
|
475
|
+
this.m_empty_msg,
|
|
476
|
+
]);
|
|
477
|
+
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
private _on_col_resize(col, width) {
|
|
481
|
+
this.m_columns[col].width = width;
|
|
482
|
+
this.m_columns[col].flex = undefined;
|
|
483
|
+
this._updateScroll(true);
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
/**
|
|
487
|
+
*
|
|
488
|
+
*/
|
|
489
|
+
|
|
490
|
+
private _sortCol(col: GridColumn ) {
|
|
491
|
+
|
|
492
|
+
if (col.sortable === false) {
|
|
493
|
+
return;
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
this.m_columns.forEach((c) => {
|
|
497
|
+
if (c !== col) {
|
|
498
|
+
(<any>c).$sorted = false;
|
|
499
|
+
(<any>c).$col.removeClass('sort desc');
|
|
500
|
+
}
|
|
501
|
+
});
|
|
502
|
+
|
|
503
|
+
const $col = col as any;
|
|
504
|
+
|
|
505
|
+
if ($col.$sorted) {
|
|
506
|
+
$col.$sens = $col.$sens ? 0 : 1;
|
|
507
|
+
$col.$col.setClass('desc', $col.$sens);
|
|
508
|
+
}
|
|
509
|
+
else {
|
|
510
|
+
$col.$sens = 0;
|
|
511
|
+
$col.$sorted = true;
|
|
512
|
+
$col.$col.addClass('sort');
|
|
513
|
+
$col.$col.removeClass('desc');
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
if (this.m_dataview) {
|
|
517
|
+
this.m_dataview.sort([
|
|
518
|
+
{ field: col.id, ascending: $col.$sens ? false : true }
|
|
519
|
+
]);
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
/**
|
|
524
|
+
*
|
|
525
|
+
*/
|
|
526
|
+
|
|
527
|
+
private _computeItemHeight() {
|
|
528
|
+
let gr = document.createElement('div');
|
|
529
|
+
gr.classList.add('x-row');
|
|
530
|
+
|
|
531
|
+
let gv = document.createElement('div');
|
|
532
|
+
gv.classList.add('x-grid-view');
|
|
533
|
+
gv.style.position = 'absolute';
|
|
534
|
+
gv.style.top = '-1000px';
|
|
535
|
+
gv.appendChild(gr);
|
|
536
|
+
|
|
537
|
+
this.dom.appendChild(gv);
|
|
538
|
+
let rc = gr.getBoundingClientRect();
|
|
539
|
+
this.dom.removeChild(gv);
|
|
540
|
+
|
|
541
|
+
this.m_itemHeight = rc.height;
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
private _createRow( props: CProps ): Component {
|
|
545
|
+
|
|
546
|
+
let row: Component;
|
|
547
|
+
if (this.m_recycler.length) {
|
|
548
|
+
row = this.m_recycler.pop();
|
|
549
|
+
row.clearClasses();
|
|
550
|
+
row.addClass( props.cls );
|
|
551
|
+
row.setContent( props.content );
|
|
552
|
+
row.setStyle( props.style );
|
|
553
|
+
|
|
554
|
+
for( let n in props.data ) {
|
|
555
|
+
row.setData( n, props.data[n] );
|
|
556
|
+
}
|
|
557
|
+
}
|
|
558
|
+
else {
|
|
559
|
+
row = new HLayout( props );
|
|
560
|
+
}
|
|
561
|
+
|
|
562
|
+
if (!row.dom) {
|
|
563
|
+
this.m_container.appendChild(row);
|
|
564
|
+
}
|
|
565
|
+
|
|
566
|
+
return row;
|
|
567
|
+
}
|
|
568
|
+
|
|
569
|
+
private _buildItems( canOpt = true ) {
|
|
570
|
+
let rc = this.getBoundingRect();
|
|
571
|
+
let rh = this.m_header.getBoundingRect();
|
|
572
|
+
let height = rc.height - rh.height + this.m_itemHeight;
|
|
573
|
+
|
|
574
|
+
if (this.m_itemHeight == 0) {
|
|
575
|
+
this._computeItemHeight();
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
let top = this.m_topIndex * this.m_itemHeight;
|
|
579
|
+
let y = 0;
|
|
580
|
+
let cidx = 0;
|
|
581
|
+
let index = this.m_topIndex;
|
|
582
|
+
let count = this.m_dataview ? this.m_dataview.count : 0;
|
|
583
|
+
let full_width = 0;
|
|
584
|
+
let even = this.m_topIndex & 1 ? true : false;
|
|
585
|
+
|
|
586
|
+
// compute full width
|
|
587
|
+
this.m_columns.forEach((col) => {
|
|
588
|
+
full_width += col.width ?? 0;
|
|
589
|
+
});
|
|
590
|
+
|
|
591
|
+
// if items height make scroll visible, update header width
|
|
592
|
+
if (((count + 1) * this.m_itemHeight) >= height) {
|
|
593
|
+
let w = Component.getScrollbarSize();
|
|
594
|
+
this.m_header.setStyleValue("paddingRight", w);
|
|
595
|
+
this.m_footer?.setStyleValue("paddingRight", w);
|
|
596
|
+
}
|
|
597
|
+
else {
|
|
598
|
+
this.m_header.setStyleValue("paddingRight", 0);
|
|
599
|
+
this.m_footer?.setStyleValue("paddingRight", 0);
|
|
600
|
+
}
|
|
601
|
+
|
|
602
|
+
// passe 0 - all created cells are moved to the recycler
|
|
603
|
+
if( this.m_visible_rows ) {
|
|
604
|
+
this.m_visible_rows.forEach((c) => {
|
|
605
|
+
this.m_recycler.push(c);
|
|
606
|
+
});
|
|
607
|
+
}
|
|
608
|
+
|
|
609
|
+
this.m_visible_rows = [];
|
|
610
|
+
let limit = 100;
|
|
611
|
+
while (y < height && index < count && --limit > 0) {
|
|
612
|
+
|
|
613
|
+
let rec = this.m_dataview.getByIndex(index);
|
|
614
|
+
let rowid = rec.getID();
|
|
615
|
+
|
|
616
|
+
let crow = canOpt ? this.m_recycler.findIndex( ( r ) => r.getData('row-id')==rowid ) : -1;
|
|
617
|
+
if( crow>=0 ) {
|
|
618
|
+
let rrow = this.m_recycler.splice( crow, 1 )[ 0 ];
|
|
619
|
+
rrow.setStyle( {
|
|
620
|
+
top: y + top,
|
|
621
|
+
minWidth: full_width,
|
|
622
|
+
} );
|
|
623
|
+
|
|
624
|
+
if (this.m_hasMarks) {
|
|
625
|
+
rrow.setClass( '@marked', this.m_marks.has(rowid) );
|
|
626
|
+
}
|
|
627
|
+
|
|
628
|
+
rrow.removeClass( '@hidden' );
|
|
629
|
+
rrow.setClass( '@selected', this.m_selection === rowid );
|
|
630
|
+
|
|
631
|
+
this.m_visible_rows[cidx] = rrow;
|
|
632
|
+
}
|
|
633
|
+
else {
|
|
634
|
+
let cols = this.m_columns.map( col => {
|
|
635
|
+
|
|
636
|
+
let cls = '@cell';
|
|
637
|
+
if (col.align) {
|
|
638
|
+
cls += ' ' + col.align;
|
|
639
|
+
}
|
|
640
|
+
|
|
641
|
+
if (col.cls) {
|
|
642
|
+
cls += ' ' + col.cls;
|
|
643
|
+
}
|
|
644
|
+
|
|
645
|
+
let cell: Component;
|
|
646
|
+
if (col.renderer) {
|
|
647
|
+
cell = col.renderer(rec);
|
|
648
|
+
if (cell) {
|
|
649
|
+
cell.addClass(cls);
|
|
650
|
+
cell.setStyleValue('width', col.width);
|
|
651
|
+
if (col.flex !== undefined) {
|
|
652
|
+
cell.addClass('@flex');
|
|
653
|
+
cell.setStyleValue('flex', col.flex);
|
|
654
|
+
}
|
|
655
|
+
}
|
|
656
|
+
}
|
|
657
|
+
else {
|
|
658
|
+
|
|
659
|
+
let fmt = col.formatter;
|
|
660
|
+
let text;
|
|
661
|
+
|
|
662
|
+
if (fmt && fmt instanceof Function) {
|
|
663
|
+
text = fmt(rec.getRaw(col.id), rec);
|
|
664
|
+
}
|
|
665
|
+
else {
|
|
666
|
+
text = rec.getField(col.id);
|
|
667
|
+
}
|
|
668
|
+
|
|
669
|
+
cell = new Component({
|
|
670
|
+
cls,
|
|
671
|
+
width: col.width,
|
|
672
|
+
content: html`<span>${text}</span>`,
|
|
673
|
+
flex: col.flex
|
|
674
|
+
})
|
|
675
|
+
}
|
|
676
|
+
|
|
677
|
+
return cell;
|
|
678
|
+
});
|
|
679
|
+
|
|
680
|
+
let cls = '@row @hlayout center';
|
|
681
|
+
if (this.m_hasMarks) {
|
|
682
|
+
if (this.m_marks.has(rowid)) {
|
|
683
|
+
cls += ' @marked';
|
|
684
|
+
}
|
|
685
|
+
}
|
|
686
|
+
|
|
687
|
+
if (this.m_selection === rowid) {
|
|
688
|
+
cls += ' @selected';
|
|
689
|
+
}
|
|
690
|
+
|
|
691
|
+
let row = this.m_visible_rows[cidx] = this._createRow( {
|
|
692
|
+
cls,
|
|
693
|
+
content: <any>cols,
|
|
694
|
+
style: {
|
|
695
|
+
top: y + top,
|
|
696
|
+
minWidth: full_width,
|
|
697
|
+
},
|
|
698
|
+
data: {
|
|
699
|
+
'row-id': rowid,
|
|
700
|
+
'row-idx': index
|
|
701
|
+
}
|
|
702
|
+
});
|
|
703
|
+
|
|
704
|
+
row.addClass(even ? 'even' : 'odd');
|
|
705
|
+
even = !even;
|
|
706
|
+
|
|
707
|
+
if (this.m_rowClassifier) {
|
|
708
|
+
this.m_rowClassifier(rec, row);
|
|
709
|
+
}
|
|
710
|
+
}
|
|
711
|
+
|
|
712
|
+
y += this.m_itemHeight;
|
|
713
|
+
|
|
714
|
+
index++;
|
|
715
|
+
cidx++;
|
|
716
|
+
}
|
|
717
|
+
|
|
718
|
+
// if some cells are still in cache, hide them
|
|
719
|
+
this.m_recycler.forEach((c) => {
|
|
720
|
+
c.addClass('@hidden');
|
|
721
|
+
})
|
|
722
|
+
|
|
723
|
+
//this.m_container.setContent(<ComponentContent>this.m_visible_rows);
|
|
724
|
+
|
|
725
|
+
let show = !count;
|
|
726
|
+
let msg = (this.m_empty_text instanceof Function) ? this.m_empty_text() : this.m_empty_text;
|
|
727
|
+
this.m_empty_msg.text = msg;
|
|
728
|
+
|
|
729
|
+
if (show && msg.length == 0) {
|
|
730
|
+
show = false;
|
|
731
|
+
}
|
|
732
|
+
|
|
733
|
+
this.m_empty_msg.show(show);
|
|
734
|
+
|
|
735
|
+
if (full_width < rc.width) {
|
|
736
|
+
this.m_header.setStyleValue('width', null);
|
|
737
|
+
this.m_footer?.setStyleValue('width', null);
|
|
738
|
+
this.m_container.setStyle({
|
|
739
|
+
height: count * this.m_itemHeight,
|
|
740
|
+
width: null
|
|
741
|
+
});
|
|
742
|
+
}
|
|
743
|
+
else {
|
|
744
|
+
this.m_header.setStyleValue('width', full_width);
|
|
745
|
+
this.m_footer?.setStyleValue('width', full_width);
|
|
746
|
+
|
|
747
|
+
this.m_container.setStyle({
|
|
748
|
+
height: count * this.m_itemHeight,
|
|
749
|
+
width: full_width
|
|
750
|
+
});
|
|
751
|
+
}
|
|
752
|
+
}
|
|
753
|
+
|
|
754
|
+
/**
|
|
755
|
+
*
|
|
756
|
+
*/
|
|
757
|
+
|
|
758
|
+
private _updateScroll(forceUpdate) {
|
|
759
|
+
if (!this.m_view_el || !this.m_view_el.dom) {
|
|
760
|
+
return;
|
|
761
|
+
}
|
|
762
|
+
|
|
763
|
+
const update = () => {
|
|
764
|
+
let newTop = Math.floor(this.m_view_el.dom.scrollTop / (this.m_itemHeight || 1));
|
|
765
|
+
|
|
766
|
+
if (newTop != this.m_topIndex || forceUpdate) {
|
|
767
|
+
this.m_topIndex = newTop;
|
|
768
|
+
this._buildItems( !forceUpdate );
|
|
769
|
+
}
|
|
770
|
+
|
|
771
|
+
let newLeft = this.m_view_el.dom.scrollLeft;
|
|
772
|
+
this.m_header.setStyleValue('left', -newLeft);
|
|
773
|
+
this.m_footer?.setStyleValue('left', -newLeft);
|
|
774
|
+
}
|
|
775
|
+
|
|
776
|
+
if (forceUpdate) {
|
|
777
|
+
this.singleShot( update, 10 );
|
|
778
|
+
}
|
|
779
|
+
else {
|
|
780
|
+
update();
|
|
781
|
+
}
|
|
782
|
+
}
|
|
783
|
+
|
|
784
|
+
/** @ignore */
|
|
785
|
+
|
|
786
|
+
private _rowFromTarget(dom) {
|
|
787
|
+
let self = this.dom;
|
|
788
|
+
|
|
789
|
+
while (dom && dom != self) {
|
|
790
|
+
let itm = Component.getElement(dom);
|
|
791
|
+
|
|
792
|
+
if (itm) {
|
|
793
|
+
let id = itm.getData('row-id');
|
|
794
|
+
if (id !== undefined) {
|
|
795
|
+
return { id, itm };
|
|
796
|
+
}
|
|
797
|
+
}
|
|
798
|
+
|
|
799
|
+
dom = dom.parentElement;
|
|
800
|
+
}
|
|
801
|
+
|
|
802
|
+
return undefined;
|
|
803
|
+
}
|
|
804
|
+
|
|
805
|
+
private _itemClick(e: MouseEvent) {
|
|
806
|
+
let hit = this._rowFromTarget(e.target);
|
|
807
|
+
if (hit) {
|
|
808
|
+
this._selectItem(hit.id, hit.itm);
|
|
809
|
+
}
|
|
810
|
+
else {
|
|
811
|
+
this._selectItem(undefined, undefined);
|
|
812
|
+
}
|
|
813
|
+
}
|
|
814
|
+
|
|
815
|
+
private _itemDblClick(e: MouseEvent) {
|
|
816
|
+
let hit = this._rowFromTarget(e.target);
|
|
817
|
+
if (hit) {
|
|
818
|
+
this._selectItem(hit.id, hit.itm);
|
|
819
|
+
|
|
820
|
+
let rec = this.m_dataview.getById(hit.id);
|
|
821
|
+
this.emit( 'dblClick', EvDblClick(rec) );
|
|
822
|
+
|
|
823
|
+
if (this.m_hasMarks) {
|
|
824
|
+
this._toggleMark(rec);
|
|
825
|
+
}
|
|
826
|
+
}
|
|
827
|
+
|
|
828
|
+
}
|
|
829
|
+
|
|
830
|
+
/** @ignore */
|
|
831
|
+
private _itemMenu(e: MouseEvent) {
|
|
832
|
+
|
|
833
|
+
let dom = e.target as HTMLElement,
|
|
834
|
+
self = this.dom;
|
|
835
|
+
|
|
836
|
+
while (dom && dom != self) {
|
|
837
|
+
let itm = Component.getElement(dom),
|
|
838
|
+
id = itm?.getData('row-id');
|
|
839
|
+
|
|
840
|
+
if (id !== undefined) {
|
|
841
|
+
this._selectItem(id, itm);
|
|
842
|
+
|
|
843
|
+
let idx = itm.getData('row-idx');
|
|
844
|
+
let rec = this.m_dataview.getByIndex(idx);
|
|
845
|
+
|
|
846
|
+
this._showItemContextMenu(e, rec);
|
|
847
|
+
e.preventDefault();
|
|
848
|
+
return;
|
|
849
|
+
}
|
|
850
|
+
|
|
851
|
+
dom = dom.parentElement;
|
|
852
|
+
}
|
|
853
|
+
}
|
|
854
|
+
|
|
855
|
+
/**
|
|
856
|
+
*
|
|
857
|
+
*/
|
|
858
|
+
|
|
859
|
+
private _findItem(id): Component {
|
|
860
|
+
|
|
861
|
+
for (let i = 0; i < this.m_visible_rows.length; i++) {
|
|
862
|
+
let itm = this.m_visible_rows[i];
|
|
863
|
+
if (itm.getData('row-id') === id) {
|
|
864
|
+
return itm;
|
|
865
|
+
}
|
|
866
|
+
}
|
|
867
|
+
|
|
868
|
+
return null;
|
|
869
|
+
}
|
|
870
|
+
|
|
871
|
+
/**
|
|
872
|
+
* @ignore
|
|
873
|
+
* called when an item is selected by mouse
|
|
874
|
+
*/
|
|
875
|
+
|
|
876
|
+
protected _selectItem(item: any, dom_item: Component, scrollIntoView?: string) {
|
|
877
|
+
|
|
878
|
+
if (this.m_selection !== undefined) {
|
|
879
|
+
let old = this._findItem(this.m_selection);
|
|
880
|
+
if (old) {
|
|
881
|
+
old.removeClass('@selected');
|
|
882
|
+
}
|
|
883
|
+
}
|
|
884
|
+
|
|
885
|
+
this.m_selection = item;
|
|
886
|
+
|
|
887
|
+
if (item) {
|
|
888
|
+
if (scrollIntoView) {
|
|
889
|
+
this._scrollIntoView(item, scrollIntoView);
|
|
890
|
+
}
|
|
891
|
+
|
|
892
|
+
if (!dom_item) {
|
|
893
|
+
dom_item = this._findItem(item);
|
|
894
|
+
}
|
|
895
|
+
|
|
896
|
+
if (dom_item) {
|
|
897
|
+
dom_item.addClass('@selected');
|
|
898
|
+
}
|
|
899
|
+
|
|
900
|
+
let rec = this.m_dataview.getById(item);
|
|
901
|
+
this.emit( 'selectionChange', EvSelectionChange(rec));
|
|
902
|
+
}
|
|
903
|
+
else {
|
|
904
|
+
this.emit( 'selectionChange', EvSelectionChange(null));
|
|
905
|
+
}
|
|
906
|
+
}
|
|
907
|
+
|
|
908
|
+
/**
|
|
909
|
+
*
|
|
910
|
+
*/
|
|
911
|
+
|
|
912
|
+
protected _showItemContextMenu(event: MouseEvent, item: Record) {
|
|
913
|
+
this.emit( 'contextMenu', EvContextMenu(event,item));
|
|
914
|
+
}
|
|
915
|
+
|
|
916
|
+
/**
|
|
917
|
+
*
|
|
918
|
+
*/
|
|
919
|
+
|
|
920
|
+
public clearSelection() {
|
|
921
|
+
this._selectItem(null, null);
|
|
922
|
+
}
|
|
923
|
+
|
|
924
|
+
/**
|
|
925
|
+
* todo: moveto datastore
|
|
926
|
+
*/
|
|
927
|
+
|
|
928
|
+
public exportData(filename) {
|
|
929
|
+
|
|
930
|
+
let data = '';
|
|
931
|
+
const fsep = '\t';
|
|
932
|
+
const lsep = '\r\n';
|
|
933
|
+
|
|
934
|
+
let rec = '';
|
|
935
|
+
this.m_columns.map((col) => {
|
|
936
|
+
|
|
937
|
+
if (rec.length) {
|
|
938
|
+
rec += fsep;
|
|
939
|
+
}
|
|
940
|
+
|
|
941
|
+
rec += col.title;
|
|
942
|
+
});
|
|
943
|
+
|
|
944
|
+
data += rec + lsep;
|
|
945
|
+
|
|
946
|
+
let count = this.m_dataview.count;
|
|
947
|
+
|
|
948
|
+
for (let i = 0; i < count; i++) {
|
|
949
|
+
|
|
950
|
+
let record = this.m_dataview.getByIndex(i);
|
|
951
|
+
|
|
952
|
+
rec = '';
|
|
953
|
+
let cols = this.m_columns.map((col) => {
|
|
954
|
+
|
|
955
|
+
let text = record.getField(col.id);
|
|
956
|
+
let fmt = col.formatter;
|
|
957
|
+
|
|
958
|
+
if (fmt && fmt instanceof Function) {
|
|
959
|
+
text = fmt(text, record);
|
|
960
|
+
}
|
|
961
|
+
|
|
962
|
+
if (rec.length > 0) {
|
|
963
|
+
rec += fsep;
|
|
964
|
+
}
|
|
965
|
+
|
|
966
|
+
rec += text;
|
|
967
|
+
});
|
|
968
|
+
|
|
969
|
+
data += rec + lsep;
|
|
970
|
+
}
|
|
971
|
+
|
|
972
|
+
//todo: review that
|
|
973
|
+
data = data.replace(/[àâä]/gm, 'a');
|
|
974
|
+
data = data.replace(/[éèê]/gm, 'e');
|
|
975
|
+
data = data.replace(/[îï]/gm, 'i');
|
|
976
|
+
data = data.replace(/[ûüù]/gm, 'u');
|
|
977
|
+
data = data.replace(/ /gm, ' '); // non breaking space
|
|
978
|
+
|
|
979
|
+
downloadData(data, 'text/csv', filename);
|
|
980
|
+
}
|
|
981
|
+
|
|
982
|
+
set empty_text(text: string | HtmlString) {
|
|
983
|
+
this.m_empty_msg.text = text;
|
|
984
|
+
}
|
|
985
|
+
|
|
986
|
+
private _renderCheck(rec: Record) {
|
|
987
|
+
let cls = '';
|
|
988
|
+
if (this.m_marks.has(rec.getID())) {
|
|
989
|
+
cls = ' checked';
|
|
990
|
+
}
|
|
991
|
+
|
|
992
|
+
return new Component({ cls: '@grid-checkbox' + cls });
|
|
993
|
+
}
|
|
994
|
+
|
|
995
|
+
private _toggleMark(rec: Record) {
|
|
996
|
+
|
|
997
|
+
let id = rec.getID();
|
|
998
|
+
let chk = false;
|
|
999
|
+
|
|
1000
|
+
if (this.m_marks.has(id)) {
|
|
1001
|
+
this.m_marks.delete(id);
|
|
1002
|
+
}
|
|
1003
|
+
else {
|
|
1004
|
+
this.m_marks.add(id);
|
|
1005
|
+
chk = true;
|
|
1006
|
+
}
|
|
1007
|
+
|
|
1008
|
+
this.emit( 'gridCheck', EvGridCheck(rec, chk));
|
|
1009
|
+
this._buildItems( false );
|
|
1010
|
+
}
|
|
1011
|
+
|
|
1012
|
+
public getMarks(): any[] {
|
|
1013
|
+
let ids = [];
|
|
1014
|
+
for (const v of this.m_marks.values()) {
|
|
1015
|
+
ids.push(v);
|
|
1016
|
+
}
|
|
1017
|
+
|
|
1018
|
+
return ids;
|
|
1019
|
+
}
|
|
1020
|
+
|
|
1021
|
+
public clearMarks() {
|
|
1022
|
+
if (this.m_marks.size) {
|
|
1023
|
+
this.m_marks = new Set<any>();
|
|
1024
|
+
this._buildItems( false );
|
|
1025
|
+
}
|
|
1026
|
+
}
|
|
1027
|
+
|
|
1028
|
+
public setFooterData( rec: any ) {
|
|
1029
|
+
if( !this.m_footer ) {
|
|
1030
|
+
return;
|
|
1031
|
+
}
|
|
1032
|
+
|
|
1033
|
+
this.m_footer.enumChilds( (c) => {
|
|
1034
|
+
let cid = c.getData( 'col' );
|
|
1035
|
+
let col = this.m_columns[cid];
|
|
1036
|
+
|
|
1037
|
+
let fmt = col.formatter;
|
|
1038
|
+
|
|
1039
|
+
let text;
|
|
1040
|
+
if (fmt && fmt instanceof Function) {
|
|
1041
|
+
text = fmt(rec[col.id], rec);
|
|
1042
|
+
}
|
|
1043
|
+
else {
|
|
1044
|
+
text = rec[col.id];
|
|
1045
|
+
}
|
|
1046
|
+
|
|
1047
|
+
c.setContent( text, false );
|
|
1048
|
+
});
|
|
1049
|
+
}
|
|
1050
|
+
}
|
|
1051
|
+
|