@cdmx/wappler_ag_grid 0.9.0 → 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 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.
@@ -37,6 +37,11 @@
37
37
  "name": "fileData",
38
38
  "title": "fileData",
39
39
  "type": "array"
40
+ },
41
+ {
42
+ "name": "selectedRows",
43
+ "title": "selectedRows",
44
+ "type": "array"
40
45
  }
41
46
  ],
42
47
  "outputType": "object",
@@ -1853,9 +1858,29 @@
1853
1858
  addTitle: 'importFileData',
1854
1859
  title: 'Import File Data',
1855
1860
  name: 'importFileData',
1856
- icon: 'fa fa-lg fa-undo',
1861
+ icon: 'fa fa-lg fa-file-import',
1857
1862
  state: 'opened',
1858
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',
1859
1884
  properties: []
1860
1885
  }
1861
1886
  ],
@@ -1870,6 +1895,10 @@
1870
1895
  "src": "../../../node_modules/papaparse/papaparse.js",
1871
1896
  "dst": "js/papaparse.js"
1872
1897
  },
1898
+ {
1899
+ "src": "../../../node_modules/exceljs/dist/exceljs.min.js",
1900
+ "dst": "js/exceljs.min.js"
1901
+ },
1873
1902
  {
1874
1903
  "src": "../../../node_modules/ag-grid-community/styles/ag-theme-alpine.css",
1875
1904
  "dst": "css/ag-theme-alpine.css"
@@ -1910,6 +1939,11 @@
1910
1939
  "type": "js",
1911
1940
  "defer": true
1912
1941
  },
1942
+ {
1943
+ "src": "js/exceljs.min.js",
1944
+ "type": "js",
1945
+ "defer": true
1946
+ },
1913
1947
  {
1914
1948
  "src": "js/dmx-ag-grid.js",
1915
1949
  "type": "js",
package/dmx-ag-grid.js CHANGED
@@ -4,7 +4,8 @@ dmx.Component('ag-grid', {
4
4
  data: {},
5
5
  count: Number,
6
6
  fields: {},
7
- fileData: []
7
+ fileData: [],
8
+ selectedRows: []
8
9
  },
9
10
 
10
11
  attributes: {
@@ -188,12 +189,11 @@ dmx.Component('ag-grid', {
188
189
  this.set('gridInstance', gridInstance);
189
190
  }, this);
190
191
  },
191
- importFileData: function () {
192
- this.parseFileData();
193
- dmx.nextTick(function() {
194
- let gridInstance = this.refreshGrid();
195
- this.set('gridInstance', gridInstance);
196
- }, this);
192
+ importFileData: async function (fieldId) {
193
+ await this.parseFileData(fieldId);
194
+ },
195
+ getSelectedRows: function () {
196
+ exportSelectedRows();
197
197
  }
198
198
  },
199
199
 
@@ -227,7 +227,7 @@ dmx.Component('ag-grid', {
227
227
  console.error('AG Grid instance or transaction not found.');
228
228
  }
229
229
  },
230
- parseFileData: async function (options) {
230
+ parseFileData: async function (fieldId) {
231
231
  const parseCSV = (csvData) => {
232
232
  return new Promise((resolve, reject) => {
233
233
  Papa.parse(csvData, {
@@ -242,24 +242,69 @@ dmx.Component('ag-grid', {
242
242
  });
243
243
  });
244
244
  };
245
- const fileInput = document.getElementById('csv-file');
246
- const file = fileInput.files[0];
247
- if (!file) {
248
- console.error('Please select a CSV file.');
249
- return;
250
- }
251
-
252
- const reader = new FileReader();
253
- reader.onload = async (e) => {
254
- const csvData = e.target.result;
255
- try {
256
- const parsedData = await parseCSV(csvData);
257
- this.set('fileData', parsedData);
258
- } catch (error) {
259
- console.error('Error parsing CSV:', error);
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;
260
299
  }
261
- };
262
- reader.readAsText(file);
300
+
301
+ this.set('fileData', parsedData);
302
+ } catch (error) {
303
+ console.error('Error parsing file:', error);
304
+ }
305
+ };
306
+
307
+ reader.readAsBinaryString(file);
263
308
  },
264
309
  refreshGrid: function () {
265
310
  const options = this.props
@@ -1200,8 +1245,10 @@ dmx.Component('ag-grid', {
1200
1245
  }
1201
1246
  });
1202
1247
  }
1203
- const gridId = `${options.id}-grid`;
1204
- const agGridElement = document.getElementById(gridId);
1248
+ exportSelectedRows = () => {
1249
+ const selectedRows = gridConfig.api.getSelectedRows();
1250
+ this.set('selectedRows', selectedRows);
1251
+ }
1205
1252
  function updateHoveringBarStyles() {
1206
1253
  const existingStyle = document.getElementById('hovering-bar-style');
1207
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.9.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",
@@ -15,6 +15,7 @@
15
15
  ],
16
16
  "dependencies": {
17
17
  "ag-grid-community": "30.1.x",
18
+ "exceljs": "^4.3.0",
18
19
  "papaparse": "^5.4.1"
19
20
  },
20
21
  "scripts": {