Components: [table] Allow columns to be hidden

Created on 12 Dec 2017  路  6Comments  路  Source: angular/components

Bug, feature request, or proposal:

Feature request

What is the expected behavior?

It would be nice to change cdkColumnDef to null or undefined programmatically to remove the column from the table

What is the current behavior?

Nothing occurs when you change the mat-header or mat-cell in mat-table.

What are the steps to reproduce?

https://stackblitz.com/edit/material2-hide-columns

What is the use-case or motivation for changing an existing behavior?

This would allow me to write a generalized component for hiding sections of the datatable for certain screen sizes, allowing mobile data-tables to be better

Most helpful comment

@crutchcorn your class variable displayColumns is only set when you are initialising the class, and not getting updated when you call test. You could either update your test method to update displayedColumns or you could change it to a get accessor

get displayedColumns() { return this.columns.map(c => c.columnDef); }

All 6 comments

The columns displayed are set on the row def so you always have control over which ones are showing.

Can you show me what you mean? The StackBlitz that I included was the only way I could see of doing this, and it didn't work as I expected.

@crutchcorn your class variable displayColumns is only set when you are initialising the class, and not getting updated when you call test. You could either update your test method to update displayedColumns or you could change it to a get accessor

get displayedColumns() { return this.columns.map(c => c.columnDef); }

I'm incredibly dumb. Thank you @benb7760

That demo has been expired. Can u update it

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._

Was this page helpful?
0 / 5 - 0 ratings

Related issues

michaelb-01 picture michaelb-01  路  3Comments

vanor89 picture vanor89  路  3Comments

vitaly-t picture vitaly-t  路  3Comments

RoxKilly picture RoxKilly  路  3Comments

alanpurple picture alanpurple  路  3Comments