Skip to content

Commit

Permalink
feat(addon-table): add requireSort option to table (taiga-family#9036)
Browse files Browse the repository at this point in the history
Co-authored-by: 40oleg <[email protected]>

(cherry picked from commit 38c5b20)
  • Loading branch information
40oleg authored and nsbarsukov committed Oct 15, 2024
1 parent 86cd056 commit 67b4bea
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
2 changes: 2 additions & 0 deletions projects/addon-table/components/table/table.options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {TuiSizeL, TuiSizeS} from '@taiga-ui/core';

export interface TuiTableOptions {
readonly direction: -1 | 1;
readonly requiredSort: boolean;
readonly open: boolean;
readonly resizable: boolean;
readonly size: TuiSizeL | TuiSizeS;
Expand All @@ -21,6 +22,7 @@ export const TUI_TABLE_DEFAULT_OPTIONS: TuiTableOptions = {
open: true,
size: 'm',
direction: 1,
requiredSort: false,
sortIcons: {
asc: 'tuiIconSortAscending',
desc: 'tuiIconSortDescending',
Expand Down
8 changes: 7 additions & 1 deletion projects/addon-table/components/table/th/th.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ export class TuiThComponent<T extends Partial<Record<keyof T, any>>> {
@HostBinding('class._sticky')
sticky = this.options.sticky;

@Input()
@HostBinding('attr.requiredSort')
requiredSort = this.options.requiredSort;

@HostBinding('style.width.px')
width: number | null = null;

Expand Down Expand Up @@ -77,8 +81,10 @@ export class TuiThComponent<T extends Partial<Record<keyof T, any>>> {
}

updateSorterAndDirection(): void {
const sorter = this.requiredSort ? this.sorter : null;

this.table?.updateSorterAndDirection(
this.isCurrentAndAscDirection ? null : this.sorter,
this.isCurrentAndAscDirection ? sorter : this.sorter,
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
*tuiHead="'age'"
tuiSortable
tuiTh
[requiredSort]="true"
>
Age
</th>
Expand Down

0 comments on commit 67b4bea

Please sign in to comment.