Skip to content

Commit

Permalink
feat(table-addon): add requireSort option to table (taiga-family#9036)
Browse files Browse the repository at this point in the history
Co-authored-by: 40oleg <oleg.merkulov701@gmail.com>
  • Loading branch information
40oleg and 40oleg authored Sep 30, 2024
1 parent 3c6e186 commit 38c5b20
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 type {TuiSizeL, TuiSizeS} from '@taiga-ui/core/types';

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: '@tui.chevron-up',
desc: '@tui.chevron-down',
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 @@ -26,6 +26,7 @@ import {TUI_TABLE_OPTIONS} from '../table.options';
host: {
'[style.width.px]': 'width',
'[class._sticky]': 'sticky',
'[attr.requiredSort]': 'requiredSort',
},
})
export class TuiTableTh<T extends Partial<Record<keyof T, any>>> {
Expand Down Expand Up @@ -53,6 +54,9 @@ export class TuiTableTh<T extends Partial<Record<keyof T, any>>> {
@Input()
public sticky = this.options.sticky;

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

public get key(): keyof T {
if (!this.head) {
throw new TuiTableSortKeyException();
Expand All @@ -76,8 +80,10 @@ export class TuiTableTh<T extends Partial<Record<keyof T, any>>> {
}

protected 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 @@ -69,6 +69,7 @@
*tuiHead="'age'"
tuiSortable
tuiTh
[requiredSort]="true"
>
Age
</th>
Expand Down

0 comments on commit 38c5b20

Please sign in to comment.