@cdmx/wappler_ag_grid 2.0.15 → 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.
Files changed (2) hide show
  1. package/dmx-ag-grid.js +36 -19
  2. 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, this.gridConfig);
363
+ exportGridData(gridInst, gridCfg);
363
364
  } else if (Pdf) {
364
- exportGridDataToPDF(gridInst, this.gridConfig);
365
+ exportGridDataToPDF(gridInst, gridCfg);
365
366
  } else {
366
367
  console.error('Grid not loaded to perform the requested export');
367
368
  }
@@ -1313,6 +1314,8 @@ dmx.Component('ag-grid', {
1313
1314
  const amountFieldsArray = options.amount_fields.split(',');
1314
1315
  if (amountFieldsArray.includes(key)) {
1315
1316
  valueFormatter = function (params) {
1317
+ const num = Number(params.value);
1318
+ if (isNaN(num)) return '-';
1316
1319
  if (params.value != null) {
1317
1320
  return Number(params.value).toLocaleString(options.date_locale, {
1318
1321
  minimumFractionDigits: options.amount_field_precision,
@@ -1325,6 +1328,7 @@ dmx.Component('ag-grid', {
1325
1328
  } else {
1326
1329
  valueFormatter = blankOrNullValueFormatter;
1327
1330
  }
1331
+ comparator = options.ci_sort ? caseInsensitiveComparator : undefined;
1328
1332
  } else if (dataType === 'date') {
1329
1333
  filter = 'agDateColumnFilter';
1330
1334
  valueFormatter = (params) => formatTime(params, timezone);
@@ -1980,10 +1984,21 @@ dmx.Component('ag-grid', {
1980
1984
  };
1981
1985
  const gridConfig = {
1982
1986
  columnDefs: columnDefs,
1983
- ...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
+ }
1984
1999
  };
1985
2000
  // Store gridConfig on component instance for export functions
1986
- this.gridConfig = gridConfig;
2001
+ this.set('gridConfig', gridConfig);
1987
2002
  // Conditionally add event listeners based on whether columnsToSum or columnsToCount are defined
1988
2003
  if ((options.columns_to_sum && options.columns_to_sum.split(',').length > 0) || (options.columns_to_count.length > 0)) {
1989
2004
  let columnsToSum = options.columns_to_sum ? options.columns_to_sum.split(',') : [];
@@ -2171,14 +2186,15 @@ dmx.Component('ag-grid', {
2171
2186
  };
2172
2187
 
2173
2188
  exportGridData = (currentGridInstance, currentGridConfig) => {
2189
+ const exportConfig = currentGridConfig.exportConfig;
2174
2190
  const excludedColumnIds = ['checkboxColumn', 'actionsColumn'];
2175
- const exportExcludeFieldsArray = options.export_exclude_fields ? options.export_exclude_fields.split(',') : [];
2191
+ const exportExcludeFieldsArray = exportConfig.export_exclude_fields ? exportConfig.export_exclude_fields.split(',') : [];
2176
2192
 
2177
2193
  let fieldsToExport = [];
2178
2194
 
2179
2195
  // Try to get saved column state from localStorage
2180
2196
  const pageId = getPageId();
2181
- const storageKey = options.column_state_storage_key || pageId;
2197
+ const storageKey = exportConfig.column_state_storage_key || pageId;
2182
2198
  const savedColumnState = localStorage.getItem(`dmxState-${storageKey}`);
2183
2199
 
2184
2200
  // If saved column state exists, use it
@@ -2212,7 +2228,7 @@ dmx.Component('ag-grid', {
2212
2228
 
2213
2229
  // Helper function to find column definition by colId
2214
2230
  function findColumnDefByColId(colId) {
2215
- if (options.group_config) {
2231
+ if (exportConfig.group_config) {
2216
2232
  const traverseColumns = (columns) => {
2217
2233
  for (const column of columns) {
2218
2234
  if (column.children) {
@@ -2238,7 +2254,7 @@ dmx.Component('ag-grid', {
2238
2254
  function getDefaultExportFields() {
2239
2255
  // Extracting fields and colIds from columnDefs
2240
2256
  let fieldsAndColIds;
2241
- if (options.group_config) {
2257
+ if (exportConfig.group_config) {
2242
2258
  // Helper function to traverse grouped column structure
2243
2259
  const traverseColumns = (columns) => {
2244
2260
  const fieldsAndColIds = [];
@@ -2266,14 +2282,14 @@ dmx.Component('ag-grid', {
2266
2282
  }
2267
2283
  const result = fieldsAndColIds.filter((column) => {
2268
2284
  return !excludedColumnIds.includes(column.colId) &&
2269
- (!options.export_exclude_hidden_fields || !column.hide) &&
2285
+ (!exportConfig.export_exclude_hidden_fields || !column.hide) &&
2270
2286
  !exportExcludeFieldsArray.includes(column.field);
2271
2287
  }).map((column) => column.field);
2272
2288
  return result;
2273
2289
  }
2274
2290
 
2275
2291
  const params = {
2276
- fileName: options.export_csv_filename,
2292
+ fileName: exportConfig.export_csv_filename,
2277
2293
  allColumns: true,
2278
2294
  columnKeys: fieldsToExport,
2279
2295
  processCellCallback: function (params) {
@@ -2304,12 +2320,12 @@ dmx.Component('ag-grid', {
2304
2320
  }
2305
2321
 
2306
2322
  // Remove HTML tags if export_remove_html is true
2307
- if (options.export_remove_html && typeof value === 'string') {
2323
+ if (exportConfig.export_remove_html && typeof value === 'string') {
2308
2324
  value = removeHtmlTags(value);
2309
2325
  }
2310
2326
 
2311
2327
  // Trim value if export_trim is true
2312
- if (options.export_trim_data && typeof value === 'string') {
2328
+ if (exportConfig.export_trim_data && typeof value === 'string') {
2313
2329
  return value.trim();
2314
2330
  }
2315
2331
 
@@ -2350,7 +2366,7 @@ dmx.Component('ag-grid', {
2350
2366
  // Always update the click handler to ensure it has the latest gridInstance and gridConfig
2351
2367
  exportButton.onclick = () => {
2352
2368
  const currentGridInstance = this.get('gridInstance');
2353
- const currentGridConfig = this.gridConfig;
2369
+ const currentGridConfig = this.get('gridConfig');
2354
2370
  if (currentGridInstance && currentGridConfig) {
2355
2371
  exportGridData(currentGridInstance, currentGridConfig);
2356
2372
  } else {
@@ -2370,10 +2386,11 @@ dmx.Component('ag-grid', {
2370
2386
  console.error('Grid API is destroyed or not initialized.');
2371
2387
  return;
2372
2388
  }
2389
+ const exportConfig = currentGridConfig.exportConfig;
2373
2390
  const excludedColumnIds = ['checkboxColumn', 'actionsColumn'];
2374
- const exportExcludeFieldsArray = options.export_exclude_fields ? options.export_exclude_fields.split(',') : [];
2391
+ const exportExcludeFieldsArray = exportConfig.export_exclude_fields ? exportConfig.export_exclude_fields.split(',') : [];
2375
2392
  let fieldsAndColIds;
2376
- if (options.group_config) {
2393
+ if (exportConfig.group_config) {
2377
2394
  // Helper function to traverse grouped column structure
2378
2395
  const traverseColumns = (columns) => {
2379
2396
  const fieldsAndColIds = [];
@@ -2401,7 +2418,7 @@ dmx.Component('ag-grid', {
2401
2418
  }
2402
2419
  const fieldsToExport = fieldsAndColIds.filter((column) => {
2403
2420
  return !excludedColumnIds.includes(column.colId) &&
2404
- (!options.export_exclude_hidden_fields || !column.hide) &&
2421
+ (!exportConfig.export_exclude_hidden_fields || !column.hide) &&
2405
2422
  !exportExcludeFieldsArray.includes(column.field);
2406
2423
  }).map((column) => column.field);
2407
2424
 
@@ -2474,7 +2491,7 @@ dmx.Component('ag-grid', {
2474
2491
  ) : headerName;
2475
2492
 
2476
2493
  // Remove HTML tags if export_remove_html is true
2477
- if (options.export_remove_html && typeof cellValue === 'string') {
2494
+ if (exportConfig.export_remove_html && typeof cellValue === 'string') {
2478
2495
  cellValue = removeHtmlTags(cellValue);
2479
2496
  }
2480
2497
 
@@ -2510,7 +2527,7 @@ dmx.Component('ag-grid', {
2510
2527
  value;
2511
2528
 
2512
2529
  // Remove HTML tags if export_remove_html is true
2513
- if (options.export_remove_html && typeof displayValue === 'string') {
2530
+ if (exportConfig.export_remove_html && typeof displayValue === 'string') {
2514
2531
  displayValue = removeHtmlTags(displayValue);
2515
2532
  }
2516
2533
 
@@ -2535,7 +2552,7 @@ dmx.Component('ag-grid', {
2535
2552
  },
2536
2553
  }],
2537
2554
  };
2538
- pdfMake.createPdf(documentDefinition).download(options.export_pdf_filename);
2555
+ pdfMake.createPdf(documentDefinition).download(exportConfig.export_pdf_filename);
2539
2556
  };
2540
2557
  if (exportToPDF) {
2541
2558
  let exportPdfButton = document.getElementById(`exportPdfButton-${options.id}`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cdmx/wappler_ag_grid",
3
- "version": "2.0.15",
3
+ "version": "2.0.17",
4
4
  "type": "module",
5
5
  "description": "App Connect module for AG Grid v34 - Advanced data grid with enhanced editing, filtering, and tree data capabilities.",
6
6
  "license": "MIT",