Skip to content

Commit

Permalink
isDefaultExpanded for for groups (#873)
Browse files Browse the repository at this point in the history
  • Loading branch information
Domino987 authored Oct 15, 2024
1 parent cf9cdf9 commit 29a8cc0
Showing 1 changed file with 36 additions and 24 deletions.
60 changes: 36 additions & 24 deletions src/utils/data-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -930,7 +930,7 @@ export default class DataManager {
this.treefied =
this.sorted =
this.paged =
false;
false;

this.filteredData = [...this.data];

Expand Down Expand Up @@ -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 = {
Expand Down Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -1403,4 +1415,4 @@ export default class DataManager {
this.changeSearchText('');
this.changePaging(0);
};
}
}

0 comments on commit 29a8cc0

Please sign in to comment.