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

feat(addon-table): add requiredSort option to table #9487

Merged
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
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')
waterplea marked this conversation as resolved.
Show resolved Hide resolved
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
Loading