@cdmx/wappler_ag_grid 0.8.9 → 0.9.1
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/README.md +10 -0
- package/app_connect/components.hjson +57 -1
- package/dmx-ag-grid.js +92 -4
- package/package.json +4 -2
package/README.md
CHANGED
|
@@ -341,6 +341,16 @@ Specify the tooltip text for Button 10.
|
|
|
341
341
|
- This action enables you to reset the grid's column state to default state.
|
|
342
342
|
- It is useful when you want to revert the column configuration to a default configuration.
|
|
343
343
|
|
|
344
|
+
**Import File Data**
|
|
345
|
+
- The "Import File Data" action allows to import data from CSV and XLSX files into the AG Grid. This action simplifies the process of populating the grid with external data sources.
|
|
346
|
+
- Key Features:
|
|
347
|
+
- File Type Support: Currently, this feature supports two common file types - CSV (Comma-Separated Values) and XLSX (Microsoft Excel).
|
|
348
|
+
- File Field ID: Users must specify the "File Field ID,"
|
|
349
|
+
|
|
350
|
+
**Get Selected Rows**
|
|
351
|
+
- The "Get Selected Rows" feature is designed to retrieve selected rows.
|
|
352
|
+
- This variable named "selectedRows", holds the selected data for access from other modules.
|
|
353
|
+
|
|
344
354
|
## License
|
|
345
355
|
|
|
346
356
|
The AG Grid module is licensed under the MIT License. Please refer to the license file for more details.
|
|
@@ -32,6 +32,16 @@
|
|
|
32
32
|
"name": "fields",
|
|
33
33
|
"title": "Fields",
|
|
34
34
|
"type": "object"
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
"name": "fileData",
|
|
38
|
+
"title": "fileData",
|
|
39
|
+
"type": "array"
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
"name": "selectedRows",
|
|
43
|
+
"title": "selectedRows",
|
|
44
|
+
"type": "array"
|
|
35
45
|
}
|
|
36
46
|
],
|
|
37
47
|
"outputType": "object",
|
|
@@ -55,7 +65,6 @@
|
|
|
55
65
|
"type": "text",
|
|
56
66
|
"dataBindings": true,
|
|
57
67
|
"defaultValue": [],
|
|
58
|
-
"required": true,
|
|
59
68
|
"help": "Enter Data Source"
|
|
60
69
|
},
|
|
61
70
|
{
|
|
@@ -1844,6 +1853,35 @@
|
|
|
1844
1853
|
state: 'opened',
|
|
1845
1854
|
help: 'Save Column State to Browser Local Storage',
|
|
1846
1855
|
properties: []
|
|
1856
|
+
},
|
|
1857
|
+
{
|
|
1858
|
+
addTitle: 'importFileData',
|
|
1859
|
+
title: 'Import File Data',
|
|
1860
|
+
name: 'importFileData',
|
|
1861
|
+
icon: 'fa fa-lg fa-file-import',
|
|
1862
|
+
state: 'opened',
|
|
1863
|
+
help: 'Import File Data to Grid',
|
|
1864
|
+
properties: [
|
|
1865
|
+
{
|
|
1866
|
+
group: 'Properties',
|
|
1867
|
+
variables: [
|
|
1868
|
+
{
|
|
1869
|
+
name: '1', optionName: '1', title: 'File Field ID', type: 'text',
|
|
1870
|
+
dataBindings: true, defaultValue: 'csvfile', required: true,
|
|
1871
|
+
help: 'Field ID of the file to import'
|
|
1872
|
+
}
|
|
1873
|
+
]
|
|
1874
|
+
}
|
|
1875
|
+
]
|
|
1876
|
+
},
|
|
1877
|
+
{
|
|
1878
|
+
addTitle: 'fetchSelectedRows',
|
|
1879
|
+
title: 'Get Selected Rows',
|
|
1880
|
+
name: 'getSelectedRows',
|
|
1881
|
+
icon: 'fas fa-lg fa-table',
|
|
1882
|
+
state: 'opened',
|
|
1883
|
+
help: 'Get Selected Rows',
|
|
1884
|
+
properties: []
|
|
1847
1885
|
}
|
|
1848
1886
|
],
|
|
1849
1887
|
"children": [],
|
|
@@ -1853,6 +1891,14 @@
|
|
|
1853
1891
|
"src": "../../../node_modules/ag-grid-community/dist/ag-grid-community.min.js",
|
|
1854
1892
|
"dst": "js/ag-grid-community.min.js"
|
|
1855
1893
|
},
|
|
1894
|
+
{
|
|
1895
|
+
"src": "../../../node_modules/papaparse/papaparse.js",
|
|
1896
|
+
"dst": "js/papaparse.js"
|
|
1897
|
+
},
|
|
1898
|
+
{
|
|
1899
|
+
"src": "../../../node_modules/exceljs/dist/exceljs.min.js",
|
|
1900
|
+
"dst": "js/exceljs.min.js"
|
|
1901
|
+
},
|
|
1856
1902
|
{
|
|
1857
1903
|
"src": "../../../node_modules/ag-grid-community/styles/ag-theme-alpine.css",
|
|
1858
1904
|
"dst": "css/ag-theme-alpine.css"
|
|
@@ -1888,6 +1934,16 @@
|
|
|
1888
1934
|
"type": "js",
|
|
1889
1935
|
"defer": true
|
|
1890
1936
|
},
|
|
1937
|
+
{
|
|
1938
|
+
"src": "js/papaparse.js",
|
|
1939
|
+
"type": "js",
|
|
1940
|
+
"defer": true
|
|
1941
|
+
},
|
|
1942
|
+
{
|
|
1943
|
+
"src": "js/exceljs.min.js",
|
|
1944
|
+
"type": "js",
|
|
1945
|
+
"defer": true
|
|
1946
|
+
},
|
|
1891
1947
|
{
|
|
1892
1948
|
"src": "js/dmx-ag-grid.js",
|
|
1893
1949
|
"type": "js",
|
package/dmx-ag-grid.js
CHANGED
|
@@ -3,7 +3,9 @@ dmx.Component('ag-grid', {
|
|
|
3
3
|
id: null,
|
|
4
4
|
data: {},
|
|
5
5
|
count: Number,
|
|
6
|
-
fields: {}
|
|
6
|
+
fields: {},
|
|
7
|
+
fileData: [],
|
|
8
|
+
selectedRows: []
|
|
7
9
|
},
|
|
8
10
|
|
|
9
11
|
attributes: {
|
|
@@ -186,6 +188,12 @@ dmx.Component('ag-grid', {
|
|
|
186
188
|
let gridInstance = this.refreshGrid();
|
|
187
189
|
this.set('gridInstance', gridInstance);
|
|
188
190
|
}, this);
|
|
191
|
+
},
|
|
192
|
+
importFileData: async function (fieldId) {
|
|
193
|
+
await this.parseFileData(fieldId);
|
|
194
|
+
},
|
|
195
|
+
getSelectedRows: function () {
|
|
196
|
+
exportSelectedRows();
|
|
189
197
|
}
|
|
190
198
|
},
|
|
191
199
|
|
|
@@ -219,7 +227,85 @@ dmx.Component('ag-grid', {
|
|
|
219
227
|
console.error('AG Grid instance or transaction not found.');
|
|
220
228
|
}
|
|
221
229
|
},
|
|
222
|
-
|
|
230
|
+
parseFileData: async function (fieldId) {
|
|
231
|
+
const parseCSV = (csvData) => {
|
|
232
|
+
return new Promise((resolve, reject) => {
|
|
233
|
+
Papa.parse(csvData, {
|
|
234
|
+
header: true,
|
|
235
|
+
dynamicTyping: true,
|
|
236
|
+
complete: function (results) {
|
|
237
|
+
resolve(results.data);
|
|
238
|
+
},
|
|
239
|
+
error: function (error) {
|
|
240
|
+
reject(error.message);
|
|
241
|
+
}
|
|
242
|
+
});
|
|
243
|
+
});
|
|
244
|
+
};
|
|
245
|
+
|
|
246
|
+
const parseExcel = (excelData) => {
|
|
247
|
+
return new Promise((resolve, reject) => {
|
|
248
|
+
const workbook = new ExcelJS.Workbook();
|
|
249
|
+
workbook.xlsx.load(excelData)
|
|
250
|
+
.then(() => {
|
|
251
|
+
const worksheet = workbook.getWorksheet(1);
|
|
252
|
+
const data = [];
|
|
253
|
+
const headers = [];
|
|
254
|
+
|
|
255
|
+
worksheet.eachRow((row, rowNumber) => {
|
|
256
|
+
if (rowNumber === 1) {
|
|
257
|
+
row.eachCell((cell) => {
|
|
258
|
+
headers.push(cell.value);
|
|
259
|
+
});
|
|
260
|
+
} else {
|
|
261
|
+
const rowData = {};
|
|
262
|
+
row.eachCell({ includeEmpty: true }, (cell, colNumber) => {
|
|
263
|
+
rowData[headers[colNumber - 1]] = cell.value;
|
|
264
|
+
});
|
|
265
|
+
data.push(rowData);
|
|
266
|
+
}
|
|
267
|
+
});
|
|
268
|
+
|
|
269
|
+
resolve(data);
|
|
270
|
+
})
|
|
271
|
+
.catch((error) => {
|
|
272
|
+
reject(error.message);
|
|
273
|
+
});
|
|
274
|
+
});
|
|
275
|
+
};
|
|
276
|
+
|
|
277
|
+
const fileInput = document.getElementById(fieldId);
|
|
278
|
+
const file = fileInput.files[0];
|
|
279
|
+
|
|
280
|
+
if (!file) {
|
|
281
|
+
console.error('Please select a file.');
|
|
282
|
+
return;
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
const reader = new FileReader();
|
|
286
|
+
reader.onload = async (e) => {
|
|
287
|
+
const fileData = e.target.result;
|
|
288
|
+
|
|
289
|
+
try {
|
|
290
|
+
let parsedData;
|
|
291
|
+
// Detect the file type based on the file extension or other criteria
|
|
292
|
+
if (file.name.endsWith('.csv')) {
|
|
293
|
+
parsedData = await parseCSV(fileData);
|
|
294
|
+
} else if (file.name.endsWith('.xlsx') || file.type === 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet') {
|
|
295
|
+
parsedData = await parseExcel(fileData);
|
|
296
|
+
} else {
|
|
297
|
+
console.error('Unsupported file type. Please select a CSV or Excel file.');
|
|
298
|
+
return;
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
this.set('fileData', parsedData);
|
|
302
|
+
} catch (error) {
|
|
303
|
+
console.error('Error parsing file:', error);
|
|
304
|
+
}
|
|
305
|
+
};
|
|
306
|
+
|
|
307
|
+
reader.readAsBinaryString(file);
|
|
308
|
+
},
|
|
223
309
|
refreshGrid: function () {
|
|
224
310
|
const options = this.props
|
|
225
311
|
const rowData = this.props.data;
|
|
@@ -1159,8 +1245,10 @@ dmx.Component('ag-grid', {
|
|
|
1159
1245
|
}
|
|
1160
1246
|
});
|
|
1161
1247
|
}
|
|
1162
|
-
|
|
1163
|
-
|
|
1248
|
+
exportSelectedRows = () => {
|
|
1249
|
+
const selectedRows = gridConfig.api.getSelectedRows();
|
|
1250
|
+
this.set('selectedRows', selectedRows);
|
|
1251
|
+
}
|
|
1164
1252
|
function updateHoveringBarStyles() {
|
|
1165
1253
|
const existingStyle = document.getElementById('hovering-bar-style');
|
|
1166
1254
|
if (options.fixed_horizontal_scroll) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cdmx/wappler_ag_grid",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "App Connect module for AG Grid Table Generation.",
|
|
6
6
|
"license": "MIT",
|
|
@@ -14,7 +14,9 @@
|
|
|
14
14
|
"ag-grid"
|
|
15
15
|
],
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"ag-grid-community": "30.1.x"
|
|
17
|
+
"ag-grid-community": "30.1.x",
|
|
18
|
+
"exceljs": "^4.3.0",
|
|
19
|
+
"papaparse": "^5.4.1"
|
|
18
20
|
},
|
|
19
21
|
"scripts": {
|
|
20
22
|
"build": "rollup --config",
|