Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Commit

Permalink
fix(table): Fixes an issue where the sorting did not update when active
Browse files Browse the repository at this point in the history
binding was updated.

When the active input for the [dtSort] was bound to a member, and this
member was updated, the table did not react to the sorting.

Fixes #619
  • Loading branch information
tomheller committed Feb 19, 2020
1 parent aca90b4 commit 6714c25
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
11 changes: 11 additions & 0 deletions components/table/src/sort/sort.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,17 @@ describe('DtSort', () => {
expect(checkCellsSorted(component.cells, true, 'column_a')).toBeTruthy();
});

it('should sort the correct column when active is being changed dynamically', () => {
component.dataSource = DATA_SOURCE;
component.start = 'asc';
component.active = 'column_a';
fixture.detectChanges();

component.active = 'column_b';
fixture.detectChanges();
expect(checkCellsSorted(component.cells, true, 'column_b')).toBeTruthy();
});

it('should keep all cells sorted if there are new rows added dynamically', () => {
component.dataSource = DATA_SOURCE;
component.start = 'asc';
Expand Down
6 changes: 6 additions & 0 deletions components/table/src/sort/sort.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,12 @@ export class DtSort extends _DtSortMixinBase
) {
this.direction = this.start;
}

// If active is bound and being changed after initialization
// we need to update the sorter.
if (isDefined(changes.active) && !changes.active.firstChange) {
this.sort(this.active, this.direction);
}
this._stateChanges.next();
}

Expand Down

0 comments on commit 6714c25

Please sign in to comment.