@cdmx/wappler_ag_grid 2.0.16 → 2.0.17
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 +33 -19
- package/package.json +1 -1
package/dmx-ag-grid.js
CHANGED
|
@@ -358,10 +358,11 @@ dmx.Component('ag-grid', {
|
|
|
358
358
|
}
|
|
359
359
|
dmx.nextTick(() => {
|
|
360
360
|
const gridInst = this.get('gridInstance');
|
|
361
|
+
const gridCfg = this.get('gridConfig');
|
|
361
362
|
if (Csv) {
|
|
362
|
-
exportGridData(gridInst,
|
|
363
|
+
exportGridData(gridInst, gridCfg);
|
|
363
364
|
} else if (Pdf) {
|
|
364
|
-
exportGridDataToPDF(gridInst,
|
|
365
|
+
exportGridDataToPDF(gridInst, gridCfg);
|
|
365
366
|
} else {
|
|
366
367
|
console.error('Grid not loaded to perform the requested export');
|
|
367
368
|
}
|
|
@@ -1983,10 +1984,21 @@ dmx.Component('ag-grid', {
|
|
|
1983
1984
|
};
|
|
1984
1985
|
const gridConfig = {
|
|
1985
1986
|
columnDefs: columnDefs,
|
|
1986
|
-
...gridOptions
|
|
1987
|
+
...gridOptions,
|
|
1988
|
+
// Store export configuration for each grid instance
|
|
1989
|
+
exportConfig: {
|
|
1990
|
+
export_csv_filename: options.export_csv_filename,
|
|
1991
|
+
export_pdf_filename: options.export_pdf_filename,
|
|
1992
|
+
export_remove_html: options.export_remove_html,
|
|
1993
|
+
export_trim_data: options.export_trim_data,
|
|
1994
|
+
export_exclude_fields: options.export_exclude_fields,
|
|
1995
|
+
export_exclude_hidden_fields: options.export_exclude_hidden_fields,
|
|
1996
|
+
group_config: options.group_config,
|
|
1997
|
+
column_state_storage_key: options.column_state_storage_key
|
|
1998
|
+
}
|
|
1987
1999
|
};
|
|
1988
2000
|
// Store gridConfig on component instance for export functions
|
|
1989
|
-
this.gridConfig
|
|
2001
|
+
this.set('gridConfig', gridConfig);
|
|
1990
2002
|
// Conditionally add event listeners based on whether columnsToSum or columnsToCount are defined
|
|
1991
2003
|
if ((options.columns_to_sum && options.columns_to_sum.split(',').length > 0) || (options.columns_to_count.length > 0)) {
|
|
1992
2004
|
let columnsToSum = options.columns_to_sum ? options.columns_to_sum.split(',') : [];
|
|
@@ -2174,14 +2186,15 @@ dmx.Component('ag-grid', {
|
|
|
2174
2186
|
};
|
|
2175
2187
|
|
|
2176
2188
|
exportGridData = (currentGridInstance, currentGridConfig) => {
|
|
2189
|
+
const exportConfig = currentGridConfig.exportConfig;
|
|
2177
2190
|
const excludedColumnIds = ['checkboxColumn', 'actionsColumn'];
|
|
2178
|
-
const exportExcludeFieldsArray =
|
|
2191
|
+
const exportExcludeFieldsArray = exportConfig.export_exclude_fields ? exportConfig.export_exclude_fields.split(',') : [];
|
|
2179
2192
|
|
|
2180
2193
|
let fieldsToExport = [];
|
|
2181
2194
|
|
|
2182
2195
|
// Try to get saved column state from localStorage
|
|
2183
2196
|
const pageId = getPageId();
|
|
2184
|
-
const storageKey =
|
|
2197
|
+
const storageKey = exportConfig.column_state_storage_key || pageId;
|
|
2185
2198
|
const savedColumnState = localStorage.getItem(`dmxState-${storageKey}`);
|
|
2186
2199
|
|
|
2187
2200
|
// If saved column state exists, use it
|
|
@@ -2215,7 +2228,7 @@ dmx.Component('ag-grid', {
|
|
|
2215
2228
|
|
|
2216
2229
|
// Helper function to find column definition by colId
|
|
2217
2230
|
function findColumnDefByColId(colId) {
|
|
2218
|
-
if (
|
|
2231
|
+
if (exportConfig.group_config) {
|
|
2219
2232
|
const traverseColumns = (columns) => {
|
|
2220
2233
|
for (const column of columns) {
|
|
2221
2234
|
if (column.children) {
|
|
@@ -2241,7 +2254,7 @@ dmx.Component('ag-grid', {
|
|
|
2241
2254
|
function getDefaultExportFields() {
|
|
2242
2255
|
// Extracting fields and colIds from columnDefs
|
|
2243
2256
|
let fieldsAndColIds;
|
|
2244
|
-
if (
|
|
2257
|
+
if (exportConfig.group_config) {
|
|
2245
2258
|
// Helper function to traverse grouped column structure
|
|
2246
2259
|
const traverseColumns = (columns) => {
|
|
2247
2260
|
const fieldsAndColIds = [];
|
|
@@ -2269,14 +2282,14 @@ dmx.Component('ag-grid', {
|
|
|
2269
2282
|
}
|
|
2270
2283
|
const result = fieldsAndColIds.filter((column) => {
|
|
2271
2284
|
return !excludedColumnIds.includes(column.colId) &&
|
|
2272
|
-
(!
|
|
2285
|
+
(!exportConfig.export_exclude_hidden_fields || !column.hide) &&
|
|
2273
2286
|
!exportExcludeFieldsArray.includes(column.field);
|
|
2274
2287
|
}).map((column) => column.field);
|
|
2275
2288
|
return result;
|
|
2276
2289
|
}
|
|
2277
2290
|
|
|
2278
2291
|
const params = {
|
|
2279
|
-
fileName:
|
|
2292
|
+
fileName: exportConfig.export_csv_filename,
|
|
2280
2293
|
allColumns: true,
|
|
2281
2294
|
columnKeys: fieldsToExport,
|
|
2282
2295
|
processCellCallback: function (params) {
|
|
@@ -2307,12 +2320,12 @@ dmx.Component('ag-grid', {
|
|
|
2307
2320
|
}
|
|
2308
2321
|
|
|
2309
2322
|
// Remove HTML tags if export_remove_html is true
|
|
2310
|
-
if (
|
|
2323
|
+
if (exportConfig.export_remove_html && typeof value === 'string') {
|
|
2311
2324
|
value = removeHtmlTags(value);
|
|
2312
2325
|
}
|
|
2313
2326
|
|
|
2314
2327
|
// Trim value if export_trim is true
|
|
2315
|
-
if (
|
|
2328
|
+
if (exportConfig.export_trim_data && typeof value === 'string') {
|
|
2316
2329
|
return value.trim();
|
|
2317
2330
|
}
|
|
2318
2331
|
|
|
@@ -2353,7 +2366,7 @@ dmx.Component('ag-grid', {
|
|
|
2353
2366
|
// Always update the click handler to ensure it has the latest gridInstance and gridConfig
|
|
2354
2367
|
exportButton.onclick = () => {
|
|
2355
2368
|
const currentGridInstance = this.get('gridInstance');
|
|
2356
|
-
const currentGridConfig = this.gridConfig;
|
|
2369
|
+
const currentGridConfig = this.get('gridConfig');
|
|
2357
2370
|
if (currentGridInstance && currentGridConfig) {
|
|
2358
2371
|
exportGridData(currentGridInstance, currentGridConfig);
|
|
2359
2372
|
} else {
|
|
@@ -2373,10 +2386,11 @@ dmx.Component('ag-grid', {
|
|
|
2373
2386
|
console.error('Grid API is destroyed or not initialized.');
|
|
2374
2387
|
return;
|
|
2375
2388
|
}
|
|
2389
|
+
const exportConfig = currentGridConfig.exportConfig;
|
|
2376
2390
|
const excludedColumnIds = ['checkboxColumn', 'actionsColumn'];
|
|
2377
|
-
const exportExcludeFieldsArray =
|
|
2391
|
+
const exportExcludeFieldsArray = exportConfig.export_exclude_fields ? exportConfig.export_exclude_fields.split(',') : [];
|
|
2378
2392
|
let fieldsAndColIds;
|
|
2379
|
-
if (
|
|
2393
|
+
if (exportConfig.group_config) {
|
|
2380
2394
|
// Helper function to traverse grouped column structure
|
|
2381
2395
|
const traverseColumns = (columns) => {
|
|
2382
2396
|
const fieldsAndColIds = [];
|
|
@@ -2404,7 +2418,7 @@ dmx.Component('ag-grid', {
|
|
|
2404
2418
|
}
|
|
2405
2419
|
const fieldsToExport = fieldsAndColIds.filter((column) => {
|
|
2406
2420
|
return !excludedColumnIds.includes(column.colId) &&
|
|
2407
|
-
(!
|
|
2421
|
+
(!exportConfig.export_exclude_hidden_fields || !column.hide) &&
|
|
2408
2422
|
!exportExcludeFieldsArray.includes(column.field);
|
|
2409
2423
|
}).map((column) => column.field);
|
|
2410
2424
|
|
|
@@ -2477,7 +2491,7 @@ dmx.Component('ag-grid', {
|
|
|
2477
2491
|
) : headerName;
|
|
2478
2492
|
|
|
2479
2493
|
// Remove HTML tags if export_remove_html is true
|
|
2480
|
-
if (
|
|
2494
|
+
if (exportConfig.export_remove_html && typeof cellValue === 'string') {
|
|
2481
2495
|
cellValue = removeHtmlTags(cellValue);
|
|
2482
2496
|
}
|
|
2483
2497
|
|
|
@@ -2513,7 +2527,7 @@ dmx.Component('ag-grid', {
|
|
|
2513
2527
|
value;
|
|
2514
2528
|
|
|
2515
2529
|
// Remove HTML tags if export_remove_html is true
|
|
2516
|
-
if (
|
|
2530
|
+
if (exportConfig.export_remove_html && typeof displayValue === 'string') {
|
|
2517
2531
|
displayValue = removeHtmlTags(displayValue);
|
|
2518
2532
|
}
|
|
2519
2533
|
|
|
@@ -2538,7 +2552,7 @@ dmx.Component('ag-grid', {
|
|
|
2538
2552
|
},
|
|
2539
2553
|
}],
|
|
2540
2554
|
};
|
|
2541
|
-
pdfMake.createPdf(documentDefinition).download(
|
|
2555
|
+
pdfMake.createPdf(documentDefinition).download(exportConfig.export_pdf_filename);
|
|
2542
2556
|
};
|
|
2543
2557
|
if (exportToPDF) {
|
|
2544
2558
|
let exportPdfButton = document.getElementById(`exportPdfButton-${options.id}`);
|
package/package.json
CHANGED