From 3204fc56cb104335c27c749a1599d3bb31692652 Mon Sep 17 00:00:00 2001 From: 40oleg <60510512+40oleg@users.noreply.github.com> Date: Mon, 30 Sep 2024 15:34:59 +0300 Subject: [PATCH 1/3] feat(addon-table): add requireSort option to table (#9036) Co-authored-by: 40oleg (cherry picked from commit 38c5b20c6e511c6be2ac8c89abcb317c1c182531) --- projects/addon-table/components/table/table.options.ts | 2 ++ projects/addon-table/components/table/th/th.component.ts | 8 +++++++- .../demo/src/modules/tables/table/examples/4/index.html | 1 + 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/projects/addon-table/components/table/table.options.ts b/projects/addon-table/components/table/table.options.ts index 5efbcd2fcd78..614c5436aab6 100644 --- a/projects/addon-table/components/table/table.options.ts +++ b/projects/addon-table/components/table/table.options.ts @@ -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; @@ -21,6 +22,7 @@ export const TUI_TABLE_DEFAULT_OPTIONS: TuiTableOptions = { open: true, size: 'm', direction: 1, + requiredSort: false, sortIcons: { asc: 'tuiIconSortAscending', desc: 'tuiIconSortDescending', diff --git a/projects/addon-table/components/table/th/th.component.ts b/projects/addon-table/components/table/th/th.component.ts index 8fc3bd3af6ed..82f2c3c3fc68 100644 --- a/projects/addon-table/components/table/th/th.component.ts +++ b/projects/addon-table/components/table/th/th.component.ts @@ -41,6 +41,10 @@ export class TuiThComponent>> { @HostBinding('class._sticky') sticky = this.options.sticky; + @Input() + @HostBinding('attr.requiredSort') + requiredSort = this.options.requiredSort; + @HostBinding('style.width.px') width: number | null = null; @@ -77,8 +81,10 @@ export class TuiThComponent>> { } updateSorterAndDirection(): void { + const sorter = this.requiredSort ? this.sorter : null; + this.table?.updateSorterAndDirection( - this.isCurrentAndAscDirection ? null : this.sorter, + this.isCurrentAndAscDirection ? sorter : this.sorter, ); } diff --git a/projects/demo/src/modules/tables/table/examples/4/index.html b/projects/demo/src/modules/tables/table/examples/4/index.html index 15f78b2797c1..8123cc6b5d6f 100644 --- a/projects/demo/src/modules/tables/table/examples/4/index.html +++ b/projects/demo/src/modules/tables/table/examples/4/index.html @@ -68,6 +68,7 @@ *tuiHead="'age'" tuiSortable tuiTh + [requiredSort]="true" > Age From 67b4beab16769d12c7610aee64154aeb25a4aa95 Mon Sep 17 00:00:00 2001 From: 40oleg <60510512+40oleg@users.noreply.github.com> Date: Mon, 30 Sep 2024 15:34:59 +0300 Subject: [PATCH 2/3] feat(addon-table): add requireSort option to table (#9036) Co-authored-by: 40oleg (cherry picked from commit 38c5b20c6e511c6be2ac8c89abcb317c1c182531) --- projects/addon-table/components/table/table.options.ts | 2 ++ projects/addon-table/components/table/th/th.component.ts | 8 +++++++- .../demo/src/modules/tables/table/examples/4/index.html | 1 + 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/projects/addon-table/components/table/table.options.ts b/projects/addon-table/components/table/table.options.ts index 5efbcd2fcd78..614c5436aab6 100644 --- a/projects/addon-table/components/table/table.options.ts +++ b/projects/addon-table/components/table/table.options.ts @@ -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; @@ -21,6 +22,7 @@ export const TUI_TABLE_DEFAULT_OPTIONS: TuiTableOptions = { open: true, size: 'm', direction: 1, + requiredSort: false, sortIcons: { asc: 'tuiIconSortAscending', desc: 'tuiIconSortDescending', diff --git a/projects/addon-table/components/table/th/th.component.ts b/projects/addon-table/components/table/th/th.component.ts index 8fc3bd3af6ed..82f2c3c3fc68 100644 --- a/projects/addon-table/components/table/th/th.component.ts +++ b/projects/addon-table/components/table/th/th.component.ts @@ -41,6 +41,10 @@ export class TuiThComponent>> { @HostBinding('class._sticky') sticky = this.options.sticky; + @Input() + @HostBinding('attr.requiredSort') + requiredSort = this.options.requiredSort; + @HostBinding('style.width.px') width: number | null = null; @@ -77,8 +81,10 @@ export class TuiThComponent>> { } updateSorterAndDirection(): void { + const sorter = this.requiredSort ? this.sorter : null; + this.table?.updateSorterAndDirection( - this.isCurrentAndAscDirection ? null : this.sorter, + this.isCurrentAndAscDirection ? sorter : this.sorter, ); } diff --git a/projects/demo/src/modules/tables/table/examples/4/index.html b/projects/demo/src/modules/tables/table/examples/4/index.html index 15f78b2797c1..8123cc6b5d6f 100644 --- a/projects/demo/src/modules/tables/table/examples/4/index.html +++ b/projects/demo/src/modules/tables/table/examples/4/index.html @@ -68,6 +68,7 @@ *tuiHead="'age'" tuiSortable tuiTh + [requiredSort]="true" > Age From 30b25baa4cba3459498ad30a8d571c3fed667492 Mon Sep 17 00:00:00 2001 From: Alexey Zezin Date: Thu, 17 Oct 2024 12:09:42 +0300 Subject: [PATCH 3/3] chore: remove requiredSort attribute binding --- projects/addon-table/components/table/th/th.component.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/projects/addon-table/components/table/th/th.component.ts b/projects/addon-table/components/table/th/th.component.ts index 82f2c3c3fc68..1b279dabb524 100644 --- a/projects/addon-table/components/table/th/th.component.ts +++ b/projects/addon-table/components/table/th/th.component.ts @@ -42,7 +42,6 @@ export class TuiThComponent>> { sticky = this.options.sticky; @Input() - @HostBinding('attr.requiredSort') requiredSort = this.options.requiredSort; @HostBinding('style.width.px')