You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Reacted by Robin Regmi, Yarkeev Denis, Eduardo Florippes, Alexander Gabriel Castañeda Estévez, official_dulin, Tomasz, Trevor Plumley, hoesv, Vlad, dlarr and 36 more
Reacted by Alexander Pavlyuk, Robin Regmi, official_dulin, Raphael Alex, Phil, sai, Patrick Magee, Sean, Tim Tharratt, Florian Wegscheider and 93 more
Reacted by tatsujb, ChrisPanthera, Arley-Fernandez-Taximo and Noam Gal
Reacted by Anders Hagebakken, Tim Tharratt, Doocaat, Quintin Orsmond, 1antares1, hoesv, Corbin Crutchley, Vlad, Trigueiro Neto, Alexander Mills and 15 more
Reacted by Trevor Plumley, 1antares1, hoesv, Vlad, Trigueiro Neto, Alexander Mills, Sofia Mihailova, Kai, Aloke Tewary, paco76 and 16 more
Reacted by Carlo Alejandro Salas, Lane Schmidt, Marcello Telles, Anshul Saxena, Bryce Oldham and hossein647
I wonder what you refer to when you say "dynamic"? Many things regarding columns can be dynamic.
If your goal is to dynamically change which columns are shown then I think the simplest approach is to change displayedColumns.
//----- What is the current behavior?
Currently all the examples are with hard coded columns, like this:
//-----
What he (and myself) are looking for is the ability to render an arbitrary number of columns with heading names taken from some underlying datasource, e.g. columns: ColumnDefinition[];
It has to be said that the current mechanism for binding md-table to a dataSource is dreadful. It should be consistent with how we *ngFor over collections to render results, only in this instance, stamp out column definitions. Same story for rows.
It seems that there is an issue with using dynamic columns inside the ng-bootstrap modal. As neither the ngx-bootstrap modal and the material2 modal seem to work when lazy loaded, I'm using ng-bootstrap. It seems that the ContentChildren don't include column defs when using *ngFor.
Hey @nasreddineskandrani - looks like a neat way of doing dynamic components. I think if we had such a feature, it would likely go the route of using CdkPortal. That said, we don't currently have plans on bringing something like this into the repository right now
@willshowell Thanks for this answer it helped me a lot. Currently I'm trying to create a generic data table where I pass only the matColumnDef and everything else is done automaticaly (Paginator, Selection, ...) Unfortunately, there is no possibility to add the mat-sort-header using the addColumn function. Is there any other possibility to do it?
I was able to use this approach to add dynamic columns to my table by specifying template from parent. However, I was not able to add pipes to template.
{ field: 'date', label: 'Date', template: (row: any) => ${row['date']} }
I want to add date pipe to this column.
This is how I am rendering cell definition. <mat-cell *matCellDef="let row"><div [innerHTML]="column.template(row)"></div></mat-cell>
UPDATE
I was able to find this example which used implementation of pipe. It is working for me. Link to My Savior
Check out this link to create the Angular Datatable(P-Table) with Dynamic Columns, pagination, sorting, column level filtering, Reordering and Resizing of Column
i am still stuck at something like this,My Table has no headers and the first column of the table is like the header.
I need a mat-table which will have columns based on an array of Object and each column will have 4 normal textfields and 8 dropdowns,and these will be pre filled with some data or empty depending on the array of Object;
I also need to insert Columns on click of a button at a later time,Now the problem is i will have to insert a key:Value pair in each of the objects and those keys should also be dynamic otherswise it will be a duplicate
I know this was marked as closed, but I have issues with this.
While I am able to have dynamic columns like this working perfectly, mat-sort-header doesn't work with it.
Apparently, if I declare each column individually it works, if I do it with the above syntax, it created the columns dynamically but the sorting doesn't work. It actually doesn't even show the sorting arrows.
Oh wow, that works thank you so much. I can't believe I missed this I litereally spent 3 hours on this and I couldn't figure it out.
Thanks a lot! Have a good day!
Reacted by Andrew Seguin
angular-automatic-lock-bot commented on Jun 28, 2021
Activity
willshowell commentedon Jul 21, 2017
For those interested, here was my approach
https://plnkr.co/edit/UntMipJO7lQVFCCSq3sZ?p=preview
EDIT: Here is a (hopefully) evergreen stackblitz with the exact same approach
https://stackblitz.com/edit/material2-beta11-vmwjpe
alexrun commentedon Jul 30, 2017
Is it possible to internationalize these dynamic columns implementation?
pueaau commentedon Aug 9, 2017
I wonder what you refer to when you say "dynamic"? Many things regarding columns can be dynamic.
If your goal is to dynamically change which columns are shown then I think the simplest approach is to change displayedColumns.
sophistyx commentedon Sep 4, 2017
I think he outlined it pretty well here:
//-----
What is the current behavior?
Currently all the examples are with hard coded columns, like this:
//-----
What he (and myself) are looking for is the ability to render an arbitrary number of columns with heading names taken from some underlying datasource, e.g. columns: ColumnDefinition[];
It has to be said that the current mechanism for binding md-table to a dataSource is dreadful. It should be consistent with how we *ngFor over collections to render results, only in this instance, stamp out column definitions. Same story for rows.
eltimmo commentedon Oct 5, 2017
Hi @willshowell. Thanks, just looking at how you approached this. I'm not sure why but the Plunker you created has stopped working.
willshowell commentedon Oct 5, 2017
@eltimmo updated the original comment!
jscharett commentedon Oct 30, 2017
Can't seem to get this working in beta 12. Always get error that cdk-table can't find column with id.
Also, if I am using the MatTableModule, do I need to pull in the CdkTableModule?
jscharett commentedon Oct 30, 2017
It seems that there is an issue with using dynamic columns inside the ng-bootstrap modal. As neither the ngx-bootstrap modal and the material2 modal seem to work when lazy loaded, I'm using ng-bootstrap. It seems that the ContentChildren don't include column defs when using *ngFor.
jscharett commentedon Oct 30, 2017
Well, looks like I am wrong. I was able to create this Stackblitz and it works, so not sure why its failing for me locally. Ugh
jscharett commentedon Oct 30, 2017
PEBCAK
37 remaining items
andrewseguin commentedon May 20, 2019
Hey @nasreddineskandrani - looks like a neat way of doing dynamic components. I think if we had such a feature, it would likely go the route of using CdkPortal. That said, we don't currently have plans on bringing something like this into the repository right now
plixxer commentedon Aug 7, 2019
Thank you good Sir, I am converting a bootstrap UI to a material UI and i was stuck on this for quite some time.
lonnenjunior commentedon Oct 25, 2019
@willshowell Thanks for this answer it helped me a lot. Currently I'm trying to create a generic data table where I pass only the matColumnDef and everything else is done automaticaly (Paginator, Selection, ...) Unfortunately, there is no possibility to add the mat-sort-header using the addColumn function. Is there any other possibility to do it?
https://stackblitz.com/edit/angular-i4dftq-urhcpg
isaif commentedon Nov 8, 2019
this works but the index of static columns is returned as undefined. Do you have any idea on how to solve this?
iamsank8 commentedon Apr 10, 2020
I was able to use this approach to add dynamic columns to my table by specifying template from parent. However, I was not able to add pipes to template.
{ field: 'date', label: 'Date', template: (row: any) =>${row['date']}}I want to add date pipe to this column.
This is how I am rendering cell definition.
<mat-cell *matCellDef="let row"><div [innerHTML]="column.template(row)"></div></mat-cell>UPDATE
I was able to find this example which used implementation of pipe. It is working for me.
Link to My Savior
tadlakha9 commentedon May 22, 2020
Check out this link to create the Angular Datatable(P-Table) with Dynamic Columns, pagination, sorting, column level filtering, Reordering and Resizing of Column
https://www.youtube.com/watch?v=zDvzBK-xyAM
parijat93sharma commentedon Aug 27, 2020
i am still stuck at something like this,My Table has no headers and the first column of the table is like the header.
I need a mat-table which will have columns based on an array of Object and each column will have 4 normal textfields and 8 dropdowns,and these will be pre filled with some data or empty depending on the array of Object;
Something like this
MY DATASOURCE AT FIRST WILL HAVE ONLY
dataSource =[{label:'Name'}
{'label':Hobby},{'label':Address},
{'label:'state'}];
Name | Arnold | Berrry | Pickachu
hobby | Football | Baseball | Cricket
Address | dropdown | dropdown | dropdown
State | multiselect | multiselect | multiselect
CAN ANYONE PLEASE HELP ME WITH THIS APPROACH ??? @isaif @paco76 @plixxer @iamsank8
I also need to insert Columns on click of a button at a later time,Now the problem is i will have to insert a key:Value pair in each of the objects and those keys should also be dynamic otherswise it will be a duplicate
kargozerov commentedon Nov 5, 2020
Khaaz commentedon May 27, 2021
I know this was marked as closed, but I have issues with this.
While I am able to have dynamic columns like this working perfectly, mat-sort-header doesn't work with it.
Apparently, if I declare each column individually it works, if I do it with the above syntax, it created the columns dynamically but the sorting doesn't work. It actually doesn't even show the sorting arrows.
andrewseguin commentedon May 27, 2021
Looks like you are missing a
mat-sort-headeron your headersKhaaz commentedon May 28, 2021
Oh wow, that works thank you so much. I can't believe I missed this I litereally spent 3 hours on this and I couldn't figure it out.
Thanks a lot! Have a good day!
angular-automatic-lock-bot commentedon Jun 28, 2021
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.