Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(addon-table): fix sorting on table with dynamic columns #6103

Merged
merged 3 commits into from
Nov 30, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {
ChangeDetectorRef,
ContentChildren,
Directive,
Inject,
Expand All @@ -8,7 +9,7 @@ import {
} from '@angular/core';
import {TuiComparator} from '@taiga-ui/addon-table/types';
import {EMPTY_QUERY} from '@taiga-ui/cdk';
import {filter, map} from 'rxjs/operators';
import {filter, map, tap} from 'rxjs/operators';

import {TuiSortableDirective} from './sortable.directive';
import {TuiTableDirective} from './table.directive';
Expand All @@ -25,11 +26,14 @@ export class TuiSortByDirective<T extends Partial<Record<keyof T, any>>> {

@Output()
readonly tuiSortByChange = this.table.sorterChange.pipe(
// recalculate ContentChildren (sortables) https://github.com/angular/angular/issues/38976
tap(() => this.cdr.detectChanges()),
filter(() => !!this.sortables.length),
vladimirpotekhin marked this conversation as resolved.
Show resolved Hide resolved
map(sorter => this.getKey(sorter)),
);

constructor(
@Inject(ChangeDetectorRef) private readonly cdr: ChangeDetectorRef,
@Inject(TuiTableDirective) private readonly table: TuiTableDirective<T>,
) {}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {Directive, DoCheck, forwardRef, Inject, OnInit} from '@angular/core';
import {Directive, forwardRef, Inject, OnInit} from '@angular/core';
import {TuiComparator} from '@taiga-ui/addon-table/types';

import {TuiThComponent} from '../th/th.component';
Expand All @@ -9,7 +9,7 @@ import {TuiTableDirective} from './table.directive';
selector: 'th[tuiTh][tuiSortable]',
})
export class TuiSortableDirective<T extends Partial<Record<keyof T, any>>>
implements DoCheck, OnInit
implements OnInit
{
constructor(
@Inject(forwardRef(() => TuiSortByDirective))
Expand All @@ -29,12 +29,6 @@ export class TuiSortableDirective<T extends Partial<Record<keyof T, any>>>
this.th.sorter = this.sorter;
}

ngDoCheck(): void {
if (this.match && this.table.sorter !== this.sorter) {
this.table.updateSorter(this.sorter);
}
}

vladimirpotekhin marked this conversation as resolved.
Show resolved Hide resolved
private get match(): boolean {
return this.sortBy.tuiSortBy === this.key;
}
Expand Down
Loading