Skip to content

Commit

Permalink
* dtable: fix sorting nested rows.
Browse files Browse the repository at this point in the history
  • Loading branch information
catouse committed Aug 7, 2024
1 parent de1dce1 commit f87ce1b
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions lib/dtable/src/plugins/nested/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ function isAllCollapsed(this: DTableNested): boolean {
return true;
}

function updateNestedMapOrders(map: Map<string, NestedRowInfo>, lastOrder = 0, ids?: string[], level = 0): number {
function updateNestedMapOrders(map: Map<string, NestedRowInfo>, lastOrder = 1, ids?: string[], level = 0): number {
if (!ids) {
ids = [...map.keys()];
}
Expand Down Expand Up @@ -314,17 +314,17 @@ const nestedPlugin: DTablePlugin<DTableNestedTypes, DTableNestedDependencies> =
});

const nestedStateMap = new Map<string, NestedRowInfo>();
rows = rows.filter(row => {
const undefinedOrder = rows.length * 100;
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 = 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;
const infoA = nestedStateMap.get(rowA.id);
const infoB = nestedStateMap.get(rowB.id);
return (infoA?.order ?? (undefinedOrder + rowA.index)) - (infoB?.order ?? (undefinedOrder + rowB.index));
});
return rows;
},
Expand Down

0 comments on commit f87ce1b

Please sign in to comment.