@cdmx/wappler_ag_grid 2.0.13 → 2.0.14
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/dmx-ag-grid.js +116 -91
- package/package.json +1 -1
package/dmx-ag-grid.js
CHANGED
|
@@ -356,9 +356,11 @@ dmx.Component('ag-grid', {
|
|
|
356
356
|
Csv = true;
|
|
357
357
|
}
|
|
358
358
|
dmx.nextTick(() => {
|
|
359
|
-
const
|
|
360
|
-
if (
|
|
361
|
-
|
|
359
|
+
const gridInst = this.get('gridInstance');
|
|
360
|
+
if (Csv) {
|
|
361
|
+
exportGridData(gridInst, this.gridConfig);
|
|
362
|
+
} else if (Pdf) {
|
|
363
|
+
exportGridDataToPDF(gridInst, this.gridConfig);
|
|
362
364
|
} else {
|
|
363
365
|
console.error('Grid not loaded to perform the requested export');
|
|
364
366
|
}
|
|
@@ -1979,6 +1981,8 @@ dmx.Component('ag-grid', {
|
|
|
1979
1981
|
columnDefs: columnDefs,
|
|
1980
1982
|
...gridOptions
|
|
1981
1983
|
};
|
|
1984
|
+
// Store gridConfig on component instance for export functions
|
|
1985
|
+
this.gridConfig = gridConfig;
|
|
1982
1986
|
// Conditionally add event listeners based on whether columnsToSum or columnsToCount are defined
|
|
1983
1987
|
if ((options.columns_to_sum && options.columns_to_sum.split(',').length > 0) || (options.columns_to_count.length > 0)) {
|
|
1984
1988
|
let columnsToSum = options.columns_to_sum ? options.columns_to_sum.split(',') : [];
|
|
@@ -2150,7 +2154,7 @@ dmx.Component('ag-grid', {
|
|
|
2150
2154
|
updateHoveringBarStyles();
|
|
2151
2155
|
|
|
2152
2156
|
//CSV Export Function
|
|
2153
|
-
exportGridData = () => {
|
|
2157
|
+
exportGridData = (currentGridInstance, currentGridConfig) => {
|
|
2154
2158
|
const excludedColumnIds = ['checkboxColumn', 'actionsColumn'];
|
|
2155
2159
|
const exportExcludeFieldsArray = options.export_exclude_fields ? options.export_exclude_fields.split(',') : [];
|
|
2156
2160
|
|
|
@@ -2204,9 +2208,9 @@ dmx.Component('ag-grid', {
|
|
|
2204
2208
|
}
|
|
2205
2209
|
return null;
|
|
2206
2210
|
};
|
|
2207
|
-
return traverseColumns(
|
|
2211
|
+
return traverseColumns(currentGridConfig.columnDefs);
|
|
2208
2212
|
} else {
|
|
2209
|
-
return
|
|
2213
|
+
return currentGridConfig.columnDefs.find((column) => column.colId === colId);
|
|
2210
2214
|
}
|
|
2211
2215
|
}
|
|
2212
2216
|
|
|
@@ -2236,9 +2240,9 @@ dmx.Component('ag-grid', {
|
|
|
2236
2240
|
return fieldsAndColIds;
|
|
2237
2241
|
};
|
|
2238
2242
|
// Traverse columnDefs to gather fields and colIds
|
|
2239
|
-
fieldsAndColIds = traverseColumns(
|
|
2243
|
+
fieldsAndColIds = traverseColumns(currentGridConfig.columnDefs);
|
|
2240
2244
|
} else {
|
|
2241
|
-
fieldsAndColIds =
|
|
2245
|
+
fieldsAndColIds = currentGridConfig.columnDefs.map((column) => ({
|
|
2242
2246
|
field: column.field,
|
|
2243
2247
|
colId: column.colId,
|
|
2244
2248
|
hide: column.hide,
|
|
@@ -2291,46 +2295,57 @@ dmx.Component('ag-grid', {
|
|
|
2291
2295
|
return value;
|
|
2292
2296
|
},
|
|
2293
2297
|
};
|
|
2294
|
-
|
|
2298
|
+
currentGridInstance.exportDataAsCsv(params);
|
|
2295
2299
|
};
|
|
2296
2300
|
// Create the export button
|
|
2297
2301
|
if (exportToCSV) {
|
|
2298
|
-
|
|
2299
|
-
|
|
2300
|
-
|
|
2301
|
-
|
|
2302
|
-
|
|
2303
|
-
|
|
2304
|
-
|
|
2305
|
-
|
|
2306
|
-
|
|
2307
|
-
|
|
2308
|
-
// Add the button text
|
|
2309
|
-
const buttonText = document.createElement('span');
|
|
2310
|
-
buttonText.innerText = ' Export to CSV';
|
|
2311
|
-
exportButton.appendChild(buttonText);
|
|
2312
|
-
exportButton.style.backgroundColor = '#4CAF50';
|
|
2313
|
-
exportButton.style.border = 'none';
|
|
2314
|
-
exportButton.style.color = 'white';
|
|
2315
|
-
exportButton.style.padding = '5px 10px';
|
|
2316
|
-
exportButton.style.textAlign = 'center';
|
|
2317
|
-
exportButton.style.textDecoration = 'none';
|
|
2318
|
-
exportButton.style.display = 'inline-block';
|
|
2319
|
-
exportButton.style.fontSize = '14px';
|
|
2320
|
-
exportButton.style.borderRadius = '5px';
|
|
2321
|
-
exportButton.style.cursor = 'pointer';
|
|
2322
|
-
exportButton.style.marginBottom = '10px';
|
|
2302
|
+
let exportButton = document.getElementById(`exportButton-${options.id}`);
|
|
2303
|
+
let isNewButton = false;
|
|
2304
|
+
if (!exportButton) {
|
|
2305
|
+
isNewButton = true;
|
|
2306
|
+
exportButton = document.createElement('button');
|
|
2307
|
+
exportButton.id = `exportButton-${options.id}`;
|
|
2308
|
+
const icon = document.createElement('i');
|
|
2309
|
+
icon.classList.add('fas', 'fa-file-csv');
|
|
2310
|
+
exportButton.appendChild(icon);
|
|
2323
2311
|
|
|
2324
|
-
|
|
2325
|
-
|
|
2326
|
-
|
|
2327
|
-
|
|
2328
|
-
|
|
2329
|
-
|
|
2312
|
+
// Add the button text
|
|
2313
|
+
const buttonText = document.createElement('span');
|
|
2314
|
+
buttonText.innerText = ' Export to CSV';
|
|
2315
|
+
exportButton.appendChild(buttonText);
|
|
2316
|
+
exportButton.style.backgroundColor = '#4CAF50';
|
|
2317
|
+
exportButton.style.border = 'none';
|
|
2318
|
+
exportButton.style.color = 'white';
|
|
2319
|
+
exportButton.style.padding = '5px 10px';
|
|
2320
|
+
exportButton.style.textAlign = 'center';
|
|
2321
|
+
exportButton.style.textDecoration = 'none';
|
|
2322
|
+
exportButton.style.display = 'inline-block';
|
|
2323
|
+
exportButton.style.fontSize = '14px';
|
|
2324
|
+
exportButton.style.borderRadius = '5px';
|
|
2325
|
+
exportButton.style.cursor = 'pointer';
|
|
2326
|
+
exportButton.style.marginBottom = '10px';
|
|
2327
|
+
}
|
|
2328
|
+
|
|
2329
|
+
// Always update the click handler to ensure it has the latest gridInstance and gridConfig
|
|
2330
|
+
exportButton.onclick = () => {
|
|
2331
|
+
const currentGridInstance = this.get('gridInstance');
|
|
2332
|
+
const currentGridConfig = this.gridConfig;
|
|
2333
|
+
if (currentGridInstance && currentGridConfig) {
|
|
2334
|
+
exportGridData(currentGridInstance, currentGridConfig);
|
|
2335
|
+
} else {
|
|
2336
|
+
console.error('Grid instance or configuration not available for export');
|
|
2337
|
+
}
|
|
2338
|
+
};
|
|
2339
|
+
|
|
2340
|
+
if (isNewButton) {
|
|
2341
|
+
// Append the export button to the grid container
|
|
2342
|
+
gridContainer.parentNode.insertBefore(exportButton, gridContainer);
|
|
2343
|
+
exportButton.style.marginBottom = '10px';
|
|
2344
|
+
}
|
|
2330
2345
|
}
|
|
2331
2346
|
// Export AG Grid data to PDF
|
|
2332
|
-
exportGridDataToPDF = async () => {
|
|
2333
|
-
if (!
|
|
2347
|
+
exportGridDataToPDF = async (currentGridInstance, currentGridConfig) => {
|
|
2348
|
+
if (!currentGridInstance || currentGridInstance.isDestroyed()) {
|
|
2334
2349
|
console.error('Grid API is destroyed or not initialized.');
|
|
2335
2350
|
return;
|
|
2336
2351
|
}
|
|
@@ -2355,9 +2370,9 @@ dmx.Component('ag-grid', {
|
|
|
2355
2370
|
return fieldsAndColIds;
|
|
2356
2371
|
};
|
|
2357
2372
|
// Traverse columnDefs to gather fields and colIds
|
|
2358
|
-
fieldsAndColIds = traverseColumns(
|
|
2373
|
+
fieldsAndColIds = traverseColumns(currentGridConfig.columnDefs);
|
|
2359
2374
|
} else {
|
|
2360
|
-
fieldsAndColIds =
|
|
2375
|
+
fieldsAndColIds = currentGridConfig.columnDefs.map((column) => ({
|
|
2361
2376
|
field: column.field,
|
|
2362
2377
|
colId: column.colId,
|
|
2363
2378
|
hide: column.hide,
|
|
@@ -2409,19 +2424,19 @@ dmx.Component('ag-grid', {
|
|
|
2409
2424
|
return options.wrap_text ? { whiteSpace: 'normal' } : null;
|
|
2410
2425
|
};
|
|
2411
2426
|
|
|
2412
|
-
const getColumnData = (
|
|
2413
|
-
|
|
2427
|
+
const getColumnData = (gInstance, isHeader) =>
|
|
2428
|
+
gInstance.getAllDisplayedColumns()
|
|
2414
2429
|
.filter(column => fieldsToExport.includes(column.getColDef().field))
|
|
2415
2430
|
.map(column => {
|
|
2416
2431
|
const colDef = column.getColDef();
|
|
2417
2432
|
const field = colDef.field;
|
|
2418
2433
|
const params = {
|
|
2419
|
-
value: isHeader ? null :
|
|
2420
|
-
data: isHeader ? null :
|
|
2421
|
-
node: isHeader ? null :
|
|
2434
|
+
value: isHeader ? null : gInstance.getValue(column, gInstance.getDisplayedRowAtIndex(0)),
|
|
2435
|
+
data: isHeader ? null : gInstance.getDisplayedRowAtIndex(0).data,
|
|
2436
|
+
node: isHeader ? null : gInstance.getDisplayedRowAtIndex(0),
|
|
2422
2437
|
colDef,
|
|
2423
2438
|
column,
|
|
2424
|
-
api:
|
|
2439
|
+
api: gInstance,
|
|
2425
2440
|
context: params.context,
|
|
2426
2441
|
};
|
|
2427
2442
|
const cellStyle = applyCellStyle(params);
|
|
@@ -2435,31 +2450,31 @@ dmx.Component('ag-grid', {
|
|
|
2435
2450
|
text: !isHeader ? (
|
|
2436
2451
|
(colDef.cellRenderer && typeof colDef.cellRenderer === 'function') ? colDef.cellRenderer(params) :
|
|
2437
2452
|
(colDef.valueFormatter && typeof colDef.valueFormatter === 'function') ? colDef.valueFormatter(params) :
|
|
2438
|
-
|
|
2453
|
+
gInstance.getValue(column, gInstance.getDisplayedRowAtIndex(0)) ?? ''
|
|
2439
2454
|
) : headerName,
|
|
2440
2455
|
color: cellStyle?.color ?? 'black',
|
|
2441
2456
|
fillColor: cellStyle?.backgroundColor ? cellStyle.backgroundColor.replace('#', '') : undefined,
|
|
2442
2457
|
};
|
|
2443
|
-
})
|
|
2458
|
+
});;
|
|
2444
2459
|
|
|
2445
|
-
const columns =
|
|
2460
|
+
const columns = currentGridInstance.getColumnState();
|
|
2446
2461
|
const columnMap = new Map(columns.map(col => [col.colId, col]));
|
|
2447
2462
|
|
|
2448
2463
|
const rows = [];
|
|
2449
|
-
|
|
2464
|
+
currentGridInstance.forEachNode(node => {
|
|
2450
2465
|
const row = fieldsToExport.map(field => {
|
|
2451
2466
|
const col = columnMap.get(field);
|
|
2452
|
-
const colDef = col ?
|
|
2467
|
+
const colDef = col ? currentGridInstance.getColumnDefs().find(def => def.colId === col.colId) : {};
|
|
2453
2468
|
const params = {
|
|
2454
|
-
value:
|
|
2469
|
+
value: currentGridInstance.getCellValue({ rowNode: node, colKey: col.colId }) ?? '-',
|
|
2455
2470
|
data: node.data,
|
|
2456
2471
|
node,
|
|
2457
2472
|
colDef,
|
|
2458
|
-
column:
|
|
2459
|
-
api:
|
|
2473
|
+
column: currentGridInstance.getColumnState().find(col => col.colId === col.colId),
|
|
2474
|
+
api: currentGridInstance,
|
|
2460
2475
|
};
|
|
2461
2476
|
const cellStyle = applyCellStyle(params);
|
|
2462
|
-
const value =
|
|
2477
|
+
const value = currentGridInstance.getCellValue({ rowNode: node, colKey: col.colId }) ?? '-';
|
|
2463
2478
|
return {
|
|
2464
2479
|
text: (colDef.cellRenderer && typeof colDef.cellRenderer === 'function') ? colDef.cellRenderer(params) :
|
|
2465
2480
|
(colDef.valueFormatter && typeof colDef.valueFormatter === 'function') ? colDef.valueFormatter(params) :
|
|
@@ -2476,7 +2491,7 @@ dmx.Component('ag-grid', {
|
|
|
2476
2491
|
table: {
|
|
2477
2492
|
headerRows: 1,
|
|
2478
2493
|
widths: fieldsToExport.map(() => `${100 / fieldsToExport.length}%`),
|
|
2479
|
-
body: [getColumnData(
|
|
2494
|
+
body: [getColumnData(currentGridInstance, true), ...rows],
|
|
2480
2495
|
heights: (rowIndex) => (rowIndex === 0 ? 40 : 15),
|
|
2481
2496
|
fillColor: (rowIndex, colIndex) => rows[rowIndex][colIndex].fillColor,
|
|
2482
2497
|
color: (rowIndex, colIndex) => rows[rowIndex][colIndex].color,
|
|
@@ -2486,39 +2501,49 @@ dmx.Component('ag-grid', {
|
|
|
2486
2501
|
pdfMake.createPdf(documentDefinition).download(options.export_pdf_filename);
|
|
2487
2502
|
};
|
|
2488
2503
|
if (exportToPDF) {
|
|
2489
|
-
|
|
2490
|
-
|
|
2491
|
-
|
|
2492
|
-
|
|
2493
|
-
|
|
2494
|
-
|
|
2495
|
-
|
|
2496
|
-
|
|
2497
|
-
|
|
2504
|
+
let exportPdfButton = document.getElementById(`exportPdfButton-${options.id}`);
|
|
2505
|
+
let isNewPdfButton = false;
|
|
2506
|
+
if (!exportPdfButton) {
|
|
2507
|
+
isNewPdfButton = true;
|
|
2508
|
+
exportPdfButton = document.createElement('button');
|
|
2509
|
+
exportPdfButton.id = `exportPdfButton-${options.id}`;
|
|
2510
|
+
const icon = document.createElement('i');
|
|
2511
|
+
icon.classList.add('fas', 'fa-file-pdf');
|
|
2512
|
+
exportPdfButton.appendChild(icon);
|
|
2498
2513
|
|
|
2499
|
-
|
|
2500
|
-
|
|
2501
|
-
|
|
2502
|
-
|
|
2503
|
-
|
|
2504
|
-
|
|
2505
|
-
|
|
2506
|
-
|
|
2507
|
-
|
|
2508
|
-
|
|
2509
|
-
|
|
2510
|
-
|
|
2511
|
-
|
|
2512
|
-
|
|
2513
|
-
|
|
2514
|
-
|
|
2515
|
-
|
|
2516
|
-
|
|
2517
|
-
|
|
2514
|
+
// Add the button text
|
|
2515
|
+
const buttonText = document.createElement('span');
|
|
2516
|
+
buttonText.innerText = ' Export to PDF';
|
|
2517
|
+
exportPdfButton.appendChild(buttonText);
|
|
2518
|
+
exportPdfButton.style.backgroundColor = '#4CAF50';
|
|
2519
|
+
exportPdfButton.style.border = 'none';
|
|
2520
|
+
exportPdfButton.style.color = 'white';
|
|
2521
|
+
exportPdfButton.style.padding = '5px 10px';
|
|
2522
|
+
exportPdfButton.style.textAlign = 'center';
|
|
2523
|
+
exportPdfButton.style.textDecoration = 'none';
|
|
2524
|
+
exportPdfButton.style.display = 'inline-block';
|
|
2525
|
+
exportPdfButton.style.fontSize = '14px';
|
|
2526
|
+
exportPdfButton.style.borderRadius = '5px';
|
|
2527
|
+
exportPdfButton.style.cursor = 'pointer';
|
|
2528
|
+
exportPdfButton.style.marginBottom = '10px';
|
|
2529
|
+
}
|
|
2530
|
+
|
|
2531
|
+
// Always update the click handler to ensure it has the latest gridInstance and gridConfig
|
|
2532
|
+
exportPdfButton.onclick = () => {
|
|
2533
|
+
const currentGridInstance = this.get('gridInstance');
|
|
2534
|
+
const currentGridConfig = this.gridConfig;
|
|
2535
|
+
if (currentGridInstance && currentGridConfig) {
|
|
2536
|
+
exportGridDataToPDF(currentGridInstance, currentGridConfig);
|
|
2537
|
+
} else {
|
|
2538
|
+
console.error('Grid instance or configuration not available for export');
|
|
2539
|
+
}
|
|
2540
|
+
};
|
|
2518
2541
|
|
|
2519
|
-
|
|
2520
|
-
|
|
2521
|
-
|
|
2542
|
+
if (isNewPdfButton) {
|
|
2543
|
+
// Append the export button to the grid container
|
|
2544
|
+
gridContainer.parentNode.insertBefore(exportPdfButton, gridContainer);
|
|
2545
|
+
exportPdfButton.style.marginBottom = '10px';
|
|
2546
|
+
}
|
|
2522
2547
|
}
|
|
2523
2548
|
const paginationPanelCss = `
|
|
2524
2549
|
/* Flexbox layout for pagination panel */
|
package/package.json
CHANGED