Skip to content

Commit

Permalink
feat(addon-table): add requiredSort option to table (#9487)
Browse files Browse the repository at this point in the history
Co-authored-by: 40oleg <[email protected]>
Co-authored-by: Alexey Zezin <[email protected]>
  • Loading branch information
3 people authored Oct 18, 2024
1 parent 086bda4 commit f2929c5
Show file tree
Hide file tree
Showing 3 changed files with 9 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
7 changes: 6 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,9 @@ export class TuiThComponent<T extends Partial<Record<keyof T, any>>> {
@HostBinding('class._sticky')
sticky = this.options.sticky;

@Input()
requiredSort = this.options.requiredSort;

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

Expand Down Expand Up @@ -77,8 +80,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 f2929c5

Please sign in to comment.