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

[Table] Let column sorting be disabled dynamically #7761

Closed
swftvsn opened this issue Oct 13, 2017 · 3 comments
Closed

[Table] Let column sorting be disabled dynamically #7761

swftvsn opened this issue Oct 13, 2017 · 3 comments
Assignees
Labels
feature This issue represents a new feature or feature request rather than a bug or bug fix P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent

Comments

@swftvsn
Copy link
Contributor

swftvsn commented Oct 13, 2017

Bug, feature request, or proposal:

Feature request

What is the expected behavior?

I need to be able to disable sorting under some circumstances on column level. I'd like to do something like [mat-sort-header]="enabled" where enabled is boolean.

What is the current behavior?

I'm not able to dynamically disable sorting

I also experimented with

@ViewChild(MatSort) sort: MatSort
//and later
this.sort.sortables.forEach((value, key) => {
  this.sort.deregister(value)
})

but for some reason this does not do anything when template is set like this:

<mat-table matSort [dataSource]="dataSource" [matSortDisableClear]="true">

    <ng-container matColumnDef="id">
      <mat-header-cell *matHeaderCellDef mat-sort-header> ID </mat-header-cell>
      <mat-cell *matCellDef="let row"> {{row.id}} </mat-cell>
    </ng-container>
.
.
.

The only way to pull this off is to have duplicate columns, one where mat-sort-header is declared and one where it is not. (And toggle the matHeaderRowDef and columns accordingly.)

@andrewseguin andrewseguin self-assigned this Oct 13, 2017
@andrewseguin andrewseguin added feature This issue represents a new feature or feature request rather than a bug or bug fix mat-table P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent and removed mat-table labels Oct 19, 2017
@andrewseguin
Copy link
Contributor

Fixed in #8643

@Gil-Epshtain
Copy link

Gil-Epshtain commented Aug 6, 2018

// demo.component.html
<ng-container *ngFor="let column of dynamicColumns" [matColumnDef]="column">
  <th mat-header-cell *matHeaderCellDef mat-sort-header [disabled]="isSortingDisabled(column)">
    {{ column }}
  </th>
  <td mat-cell *matCellDef="let element">
    {{ element[column] }}
  </td>
</ng-container>

// demo.component.ts
public isSortingDisabled(columnText: string): boolean
{
  return false; // add your logic here
}

@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 9, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feature This issue represents a new feature or feature request rather than a bug or bug fix P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants