@cdmx/wappler_ag_grid 2.0.12 → 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 +4 -0
- package/dmx-ag-grid.js +96 -31
- package/package.json +1 -1
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
|
@@ -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
|
-
|
|
2157
|
-
let
|
|
2158
|
-
|
|
2159
|
-
|
|
2160
|
-
|
|
2161
|
-
|
|
2162
|
-
|
|
2163
|
-
|
|
2164
|
-
|
|
2165
|
-
|
|
2166
|
-
|
|
2167
|
-
|
|
2168
|
-
|
|
2169
|
-
|
|
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
|
-
|
|
2174
|
-
|
|
2175
|
-
|
|
2176
|
-
|
|
2177
|
-
|
|
2178
|
-
|
|
2179
|
-
|
|
2180
|
-
|
|
2181
|
-
|
|
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