-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwith-minified.js
More file actions
113 lines (105 loc) · 3.05 KB
/
with-minified.js
File metadata and controls
113 lines (105 loc) · 3.05 KB
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
const Adaptable = window.Adaptable;
const agGridModules = window.agGridModules;
const agGridTheme = window.agGridTheme;
const dateParserAgGrid = (params) => {
const stringToDate = (date, format, delimiter) => {
const formatLowerCase = format.toLowerCase();
const formatItems = formatLowerCase.split(delimiter);
const dateItems = date.split(delimiter);
const monthIndex = formatItems.indexOf('mm');
const dayIndex = formatItems.indexOf('dd');
const yearIndex = formatItems.indexOf('yyyy');
let month = parseInt(dateItems[monthIndex], 10);
month -= 1;
const formatedDate = new Date(
parseInt(dateItems[yearIndex], 10),
month,
parseInt(dateItems[dayIndex], 10)
);
return formatedDate;
};
try {
if (params.newValue instanceof Date) {
return params.newValue;
}
return stringToDate(params.newValue, 'dd/mm/yyyy', '/');
} catch (ex) {
console.error(`Error parsing the date value: ${params.newValue} and node : `, params.node);
return null;
}
};
const shortDateFormatterAgGrid = (params) => {
const shortDateFormatter = new Intl.DateTimeFormat('en-GB');
try {
if (params.value) {
return shortDateFormatter.format(params.value);
}
} catch (ex) {
console.error(`Error formatting the date for value: ${params.value} and node : `, params.node);
}
return null;
};
const columnDefs = [
{ field: 'OrderId', cellDataType: 'number' },
{ field: 'CompanyName', cellDataType: 'text' },
{ field: 'ContactName', cellDataType: 'text' },
{ field: 'Employee', cellDataType: 'text' },
{
field: 'InvoicedCost',
editable: true,
cellDataType: 'number',
valueFormatter: 'x.toLocaleString()',
},
{
field: 'OrderDate',
cellDataType: 'date',
editable: true,
cellEditorParams: {
useFormatter: true,
},
valueParser: dateParserAgGrid,
valueFormatter: shortDateFormatterAgGrid,
},
];
const adaptableOptions = {
primaryKey: 'OrderId',
userName: 'Demo User',
adaptableId: 'Simple Adaptable Demo',
// licenseKey: 'TODO ADD YOUR LICENSE KEY HERE',
licenseKey: '',
initialState: {
Layout: {
CurrentLayout: 'Sorted Layout',
Layouts: [
{
Columns: ['OrderId', 'CompanyName', 'ContactName', 'Employee', 'InvoicedCost'],
Name: 'Default App Layout',
},
],
},
},
};
const gridOptions = {
theme: agGridTheme,
columnDefs,
rowData: null,
};
Adaptable.init(adaptableOptions, { modules: agGridModules, gridOptions }).then((api) => {
// we simulate server loading - on AdaptableReady event
api.eventApi.on('AdaptableReady', ({ adaptableApi }) => {
// we load the json orders
// import("./orders.json")
new Promise((resolve) => {
setTimeout(() => resolve({ default: window.orders }), 1000);
})
.then((data) => data.default)
.then((data) => {
console.log(data);
// add an extra timeout
setTimeout(() => {
// and then set the correct row data
adaptableApi.gridApi.addGridData(data);
}, 500);
});
});
});