@cdmx/wappler_ag_grid 2.0.11 → 2.0.13

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
@@ -609,6 +609,10 @@ You can also specify left-only conditions, where only the field name is provided
609
609
  **Export**
610
610
  - To be used if you wish to use a separate Export button instead of using the inbuilt top left-cornered Export button.
611
611
  - Trigger this action to call Export Data to CSV/PDF download action based on selected file Type.
612
+ - **Column State Integration**: When exporting data, the grid automatically respects the saved column state from localStorage. This means:
613
+ - Columns are exported in the same order as they appear in the grid (based on user's saved column arrangement)
614
+ - Hidden columns are automatically excluded from export
615
+ - If no saved column state exists, the export falls back to the default column configuration
612
616
 
613
617
  **Save Column State**
614
618
  - This action allows you to save the current state of the grid's columns, including their visibility and order, to the browser's local storage.
package/dmx-ag-grid.js CHANGED
@@ -1296,7 +1296,7 @@ dmx.Component('ag-grid', {
1296
1296
  },
1297
1297
  {
1298
1298
  displayKey: 'doesNotContain',
1299
- displayName: 'Does not Contain',
1299
+ displayName: 'Does not contain',
1300
1300
  predicate: (filterValue, cellValue) => {
1301
1301
  return !cellValue.toString().includes(filterValue.toString());
1302
1302
  }
@@ -2153,39 +2153,104 @@ dmx.Component('ag-grid', {
2153
2153
  exportGridData = () => {
2154
2154
  const excludedColumnIds = ['checkboxColumn', 'actionsColumn'];
2155
2155
  const exportExcludeFieldsArray = options.export_exclude_fields ? options.export_exclude_fields.split(',') : [];
2156
- // Extracting fields and colIds from columnDefs
2157
- let fieldsAndColIds;
2158
- if (options.group_config) {
2159
- // Helper function to traverse grouped column structure
2160
- const traverseColumns = (columns) => {
2161
- const fieldsAndColIds = [];
2162
- columns.forEach((column) => {
2163
- if (column.children) {
2164
- fieldsAndColIds.push(...traverseColumns(column.children));
2165
- } else {
2166
- fieldsAndColIds.push({
2167
- field: column.field,
2168
- colId: column.colId,
2169
- hide: column.hide,
2170
- });
2156
+
2157
+ let fieldsToExport = [];
2158
+
2159
+ // Try to get saved column state from localStorage
2160
+ const pageId = getPageId();
2161
+ const storageKey = options.column_state_storage_key || pageId;
2162
+ const savedColumnState = localStorage.getItem(`dmxState-${storageKey}`);
2163
+
2164
+ // If saved column state exists, use it
2165
+ if (savedColumnState) {
2166
+ try {
2167
+ const parsedState = JSON.parse(savedColumnState);
2168
+ // Use the saved state to determine column order and visibility
2169
+ fieldsToExport = parsedState
2170
+ .filter((col) => {
2171
+ // Skip excluded columns
2172
+ if (excludedColumnIds.includes(col.colId)) {
2173
+ return false;
2174
+ }
2175
+ // Skip hidden columns (respecting the hide property from saved state)
2176
+ if (col.hide) {
2177
+ return false;
2178
+ }
2179
+ return true;
2180
+ })
2181
+ .map((col) => {
2182
+ // Map colId to field from columnDefs
2183
+ const columnDef = findColumnDefByColId(col.colId);
2184
+ return columnDef ? columnDef.field : col.colId;
2185
+ })
2186
+ .filter((field) => !exportExcludeFieldsArray.includes(field));
2187
+ } catch (err) {
2188
+ console.warn(`Failed to parse saved column state for key: dmxState-${storageKey}`, err);
2189
+ fieldsToExport = [];
2190
+ }
2191
+ }
2192
+
2193
+ // Helper function to find column definition by colId
2194
+ function findColumnDefByColId(colId) {
2195
+ if (options.group_config) {
2196
+ const traverseColumns = (columns) => {
2197
+ for (const column of columns) {
2198
+ if (column.children) {
2199
+ const result = traverseColumns(column.children);
2200
+ if (result) return result;
2201
+ } else if (column.colId === colId) {
2202
+ return column;
2203
+ }
2171
2204
  }
2172
- });
2173
- return fieldsAndColIds;
2174
- };
2175
- // Traverse columnDefs to gather fields and colIds
2176
- fieldsAndColIds = traverseColumns(gridConfig.columnDefs);
2177
- } else {
2178
- fieldsAndColIds = gridConfig.columnDefs.map((column) => ({
2179
- field: column.field,
2180
- colId: column.colId,
2181
- hide: column.hide,
2182
- }));
2205
+ return null;
2206
+ };
2207
+ return traverseColumns(gridConfig.columnDefs);
2208
+ } else {
2209
+ return gridConfig.columnDefs.find((column) => column.colId === colId);
2210
+ }
2211
+ }
2212
+
2213
+ // Fallback to current logic if no saved state or if fieldsToExport is empty
2214
+ if (!fieldsToExport || fieldsToExport.length === 0) {
2215
+ fieldsToExport = getDefaultExportFields();
2216
+ }
2217
+
2218
+ function getDefaultExportFields() {
2219
+ // Extracting fields and colIds from columnDefs
2220
+ let fieldsAndColIds;
2221
+ if (options.group_config) {
2222
+ // Helper function to traverse grouped column structure
2223
+ const traverseColumns = (columns) => {
2224
+ const fieldsAndColIds = [];
2225
+ columns.forEach((column) => {
2226
+ if (column.children) {
2227
+ fieldsAndColIds.push(...traverseColumns(column.children));
2228
+ } else {
2229
+ fieldsAndColIds.push({
2230
+ field: column.field,
2231
+ colId: column.colId,
2232
+ hide: column.hide,
2233
+ });
2234
+ }
2235
+ });
2236
+ return fieldsAndColIds;
2237
+ };
2238
+ // Traverse columnDefs to gather fields and colIds
2239
+ fieldsAndColIds = traverseColumns(gridConfig.columnDefs);
2240
+ } else {
2241
+ fieldsAndColIds = gridConfig.columnDefs.map((column) => ({
2242
+ field: column.field,
2243
+ colId: column.colId,
2244
+ hide: column.hide,
2245
+ }));
2246
+ }
2247
+ const result = fieldsAndColIds.filter((column) => {
2248
+ return !excludedColumnIds.includes(column.colId) &&
2249
+ (!options.export_exclude_hidden_fields || !column.hide) &&
2250
+ !exportExcludeFieldsArray.includes(column.field);
2251
+ }).map((column) => column.field);
2252
+ return result;
2183
2253
  }
2184
- const fieldsToExport = fieldsAndColIds.filter((column) => {
2185
- return !excludedColumnIds.includes(column.colId) &&
2186
- (!options.export_exclude_hidden_fields || !column.hide) &&
2187
- !exportExcludeFieldsArray.includes(column.field);
2188
- }).map((column) => column.field);
2189
2254
 
2190
2255
  const params = {
2191
2256
  fileName: options.export_csv_filename,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cdmx/wappler_ag_grid",
3
- "version": "2.0.11",
3
+ "version": "2.0.13",
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",