From 29a8cc0a285b9f9b045a869bed2248d2d50b5bf2 Mon Sep 17 00:00:00 2001 From: Domino987 Date: Tue, 15 Oct 2024 16:03:38 +0200 Subject: [PATCH] isDefaultExpanded for for groups (#873) --- src/utils/data-manager.js | 60 +++++++++++++++++++++++---------------- 1 file changed, 36 insertions(+), 24 deletions(-) diff --git a/src/utils/data-manager.js b/src/utils/data-manager.js index 9eeec772..8a35c47e 100644 --- a/src/utils/data-manager.js +++ b/src/utils/data-manager.js @@ -176,8 +176,8 @@ export default class DataManager { this.tableStyleWidth = this.tableWidth === 'full' || - undefWidthCols.length > 0 || - usedWidthNotPx.length > 0 + undefWidthCols.length > 0 || + usedWidthNotPx.length > 0 ? '100%' : usedWidthPx; } @@ -930,7 +930,7 @@ export default class DataManager { this.treefied = this.sorted = this.paged = - false; + false; this.filteredData = [...this.data]; @@ -1110,14 +1110,21 @@ export default class DataManager { if (!group) { const path = [...(o.path || []), value]; + let isDefaultExpanded = false; + switch (typeof this.defaultExpanded) { + case "boolean": + isDefaultExpanded = this.defaultExpanded; + break; + case "function": + isDefaultExpanded = this.defaultExpanded(currentRow); + break; + + } const oldGroup = this.findGroupByGroupPath( this.groupedData, path ) || { - isExpanded: - typeof this.defaultExpanded === 'boolean' - ? this.defaultExpanded - : false + isExpanded: isDefaultExpanded }; group = { @@ -1227,10 +1234,15 @@ export default class DataManager { !this.columns.some((columnDef) => columnDef.tableData.filterValue) ) { if (rowData.tableData.isTreeExpanded === undefined) { - const isExpanded = - typeof this.defaultExpanded === 'boolean' - ? this.defaultExpanded - : this.defaultExpanded(rowData); + let isExpanded = false; + switch (typeof this.defaultExpanded) { + case "boolean": + isDefaultExpanded = this.defaultExpanded; + break; + case "function": + isDefaultExpanded = this.defaultExpanded(rowData); + break; + } rowData.tableData.isTreeExpanded = isExpanded; } } @@ -1279,19 +1291,19 @@ export default class DataManager { return list.sort( columnDef.tableData.groupSort === 'desc' ? (a, b) => - columnDef.customSort( - b.value, - a.value, - 'group', - columnDef.tableData.groupSort - ) + columnDef.customSort( + b.value, + a.value, + 'group', + columnDef.tableData.groupSort + ) : (a, b) => - columnDef.customSort( - a.value, - b.value, - 'group', - columnDef.tableData.groupSort - ) + columnDef.customSort( + a.value, + b.value, + 'group', + columnDef.tableData.groupSort + ) ); } else { return list.sort( @@ -1403,4 +1415,4 @@ export default class DataManager { this.changeSearchText(''); this.changePaging(0); }; -} \ No newline at end of file +}