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

🚀 - Allow tuiSortable to configured dynamically #8244

Closed
evantrimboli opened this issue Jul 29, 2024 · 5 comments · Fixed by #9384
Closed

🚀 - Allow tuiSortable to configured dynamically #8244

evantrimboli opened this issue Jul 29, 2024 · 5 comments · Fixed by #9384
Assignees
Labels
P3 This issue has low priority

Comments

@evantrimboli
Copy link
Contributor

Description

Consider the following component structure. Note this isn't intended to be 100% correct, just for illustration.

As far as I can tell, because it's not possible to dynamically add a directive, to toggle sorting using a condition, I need to branch on whether it's sortable and then repeat the th for a second time and duplicate the code.

I'm not sure of the best way to solve it, but it would be nice to be able to provide a flag to the directive which would toggle it on or off.

interface Column {
  readonly id: string
  readonly title: string
  readonly sortable: boolean
  // Other configs
}

@Component(
  selector: 'my-table',
  template: `
  <table>
    <thead tuiHead>
      <tr tuiThGroup>
      @for (c of columns(); track c.id) {
        @if (c.sortable) {
         <th tuiTh *tuiHead="c.id" tuiSortable>
            {{ c.title }}
          </th>
        } @else {
          <th tuiTh *tuiHead="c.id">
            {{ c.title }}
          </th>
        }
      }
      </tr>
    </thead>
  </table>
`
);
export Class MyTable {
  readonly columns = input<readonly Column[]>([]);
}
@waterplea waterplea added contributions welcome Architecture is clear and community can help P3 This issue has low priority and removed state: need triage labels Sep 18, 2024
@waterplea
Copy link
Collaborator

waterplea commented Sep 18, 2024

We need to allow passing true / false to tuiSortable and then look for keys only among enabled ones in TuiTableSortBy

@tsironis13
Copy link

tsironis13 commented Sep 27, 2024

Is something ready to consume regarding this? I need to enable sorting only for columns which are configured to be sortable. Otherwise, I would like to fix it in the source code if nobody has been assigned to it.

@waterplea
Copy link
Collaborator

We need to allow passing true / false to tuiSortable and then look for keys only among enabled ones in TuiTableSortBy

Here's what needs to be done, you can make a PR.

@tsironis13
Copy link

We need to allow passing true / false to tuiSortable and then look for keys only among enabled ones in TuiTableSortBy

Here's what needs to be done, you can make a PR.

@waterplea I am on it, thanks

@waterplea
Copy link
Collaborator

waterplea commented Oct 8, 2024

@evantrimboli could you clarify the issue please, the sorting is enabled dynamically by passing [sorter] value. tuiSortable is just a directive to connect sorter and column key when you operate with keys rather than sorters, for example, for server side sorting.

EDIT: Oh, nevermind, got it. Problem was that sortable overrides it in ngOnInit so it was not possible to control with just setting [sorter]="null". PR is up.

@waterplea waterplea removed the contributions welcome Architecture is clear and community can help label Oct 8, 2024
@waterplea waterplea self-assigned this Oct 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P3 This issue has low priority
3 participants