Skip to content

Commit

Permalink
* dtable: refactor sorting rows in nested plugin.
Browse files Browse the repository at this point in the history
  • Loading branch information
catouse committed Aug 2, 2024
1 parent c972bdf commit 6976e82
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions lib/dtable/src/plugins/nested/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -313,11 +313,16 @@ const nestedPlugin: DTablePlugin<DTableNestedTypes, DTableNestedDependencies> =
}
});

rows = rows.filter(row => this.getNestedRowInfo(row.id).state !== NestedRowState.hidden);
updateNestedMapOrders(this.data.nestedMap);
const nestedStateMap = new Map<string, NestedRowInfo>();
rows = rows.filter(row => {
const info = this.getNestedRowInfo(row.id)!;
nestedStateMap.set(row.id, info);
return info.state !== NestedRowState.hidden;
});
updateNestedMapOrders(nestedStateMap);
rows.sort((rowA, rowB) => {
const infoA = this.getNestedRowInfo(rowA.id);
const infoB = this.getNestedRowInfo(rowB.id);
const infoA = nestedStateMap.get(rowA.id)!;
const infoB = nestedStateMap.get(rowB.id)!;
const result = (infoA.order ?? 0) - (infoB.order ?? 0);
return result === 0 ? (rowA.index - rowB.index) : result;
});
Expand Down Expand Up @@ -355,6 +360,7 @@ const nestedPlugin: DTablePlugin<DTableNestedTypes, DTableNestedDependencies> =
result.push(<div className="dtable-nested-indent" style={{width: nestedIndent * info.level + 'px'}} />);
}
}

return result;
},
onRenderHeaderCell(result, {row, col}) {
Expand Down

0 comments on commit 6976e82

Please sign in to comment.