-
Notifications
You must be signed in to change notification settings - Fork 7
/
rows.js
115 lines (95 loc) · 2.9 KB
/
rows.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
/*
* This file is part of the grid project
* (c) Basis Europe <eu@Basis.AgGridComponents.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
export function gw_setQuickFilter(filter) {
gw_options.api.setQuickFilter(filter);
}
export function gw_expandAll() {
gw_options.api.expandAll();
}
export function gw_collapseAll() {
gw_options.api.collapseAll();
}
export function gw_setVisibleRow(index, position) {
gw_options.api.ensureIndexVisible(index, position);
}
export function gw_navigateToNextRow(params) {
let previousCell = params.previousCellDef;
let suggestedNextCell = params.nextCellDef;
const KEY_UP = 38;
const KEY_DOWN = 40;
const KEY_LEFT = 37;
const KEY_RIGHT = 39;
switch (params.key) {
case KEY_DOWN:
previousCell = params.previousCellDef;
// set selected cell on current cell + 1
gw_options.api.forEachNode((node) => {
if (previousCell.rowIndex + 1 === node.rowIndex) {
node.setSelected(true);
}
});
return suggestedNextCell;
case KEY_UP:
previousCell = params.previousCellDef;
// set selected cell on current cell - 1
gw_options.api.forEachNode((node) => {
if (previousCell.rowIndex - 1 === node.rowIndex) {
node.setSelected(true);
}
});
return suggestedNextCell;
case KEY_LEFT:
case KEY_RIGHT:
return suggestedNextCell;
default:
throw new Error("You have super strange keyboard");
}
}
export function gw_getRowNodeId(data) {
let id;
if (gw_options.hasOwnProperty('__getRowNodeId')) {
id = data[gw_options.__getRowNodeId];
}
id = id ? id : data.__ROW_INDEX;
return id;
}
export function gw_getNodeChildDetails(rowItem) {
const key = rowItem[gw_options.__getParentNodeId];
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: key ? key : -1
};
} else {
return false;
}
}
export function gw_setRowsData(json) {
gw_options.api.setRowData(json);
gw_options.rowData = json;
gw_options.api.refreshClientSideRowModel('group');
}
export function gw_setRowData(row) {
const data = row[0];
const key = gw_options.__getRowNodeId.length === 0 ? "__ROW_INDEX" : gw_options.__getRowNodeId;
gw_options.api.getRowNode(data[key]).setData(data);
gw_options.api.refreshClientSideRowModel('group');
}
export function gw_removeRow(index) {
gw_options.rowData.splice(Number(index), 1);
gw_options.api.setRowData(gw_options.rowData);
gw_options.api.refreshClientSideRowModel('group');
}
export function gw_addRows(index,rows) {
gw_options.api.updateRowData({add: rows, addIndex: index});
gw_options.api.refreshClientSideRowModel('group');
}