Angular Material table with nested data sourceAngular 7 mat-table with array in arrayAngular Material mat-table mat-cell binding to datasource of objects and propertitiesAngular HTML bindingHuge number of files generated for every Angular projectAngular2 material dialog has issues - Did you add it to @NgModule.entryComponents?Angular + Material - How to refresh a data source (mat-table)Angular Material Table Dynamic Columns without modelSorting with dynamic column - Angular materialAngular material data tableHow to skip the loop for last row of matRowDef=“let row; columns: displayedColumns;”Angular Material data Table Data sourceCan't sort mat-table

Are there any tricks to pushing a grand piano?

What's the correct way to determine turn order in this situation?

Manager told a colleague of mine I was getting fired soon

Choice of solvent during thin layer chromatography

Bothered by watching coworkers slacking off

Was the whistleblower in the Ukraine scandal legally required to make his report?

Effect of origin poles on stability?

What are some ways to season that don't rely on garlic and onions?

Quote to show students don't have to fear making mistakes

Can we calculate the orbit of exoplanets?

Redirect output on-the-fly - looks not possible in Linux, why?

How to explain that the sums of numerators over sums of denominators isn't the same as the mean of ratios?

What is the difference between increasing volume and increasing gain?

Conveying the idea of "down the road" (i.e. in the future)

Does SQL Server's serializable isolation level lock entire table

Can an NPC use the Teleport spell to affect an object they can see with the Scrying spell?

Found a minor bug, affecting 1% of users. What should QA do?

Colleague's grant application resembles my PhD thesis

How do I know how many sub-shells deep I am?

What's the difference between motherboard and chassis?

Does the DOJ's declining to investigate the Trump-Zelensky call ruin the basis for impeachment?

Are there manual checks for non EU citizens in airports when travelling inside the EU?

As a girl, how can I voice male characters effectively?

Why do personal finance apps focus on outgoings rather than income



Angular Material table with nested data source


Angular 7 mat-table with array in arrayAngular Material mat-table mat-cell binding to datasource of objects and propertitiesAngular HTML bindingHuge number of files generated for every Angular projectAngular2 material dialog has issues - Did you add it to @NgModule.entryComponents?Angular + Material - How to refresh a data source (mat-table)Angular Material Table Dynamic Columns without modelSorting with dynamic column - Angular materialAngular material data tableHow to skip the loop for last row of matRowDef=“let row; columns: displayedColumns;”Angular Material data Table Data sourceCan't sort mat-table






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty
margin-bottom:0;









1















I am showing the data of my JSON file in the mat-table. The mat-table works fine in showing the rows but I have to show the data inside an array in a row. However, I don't know what would be the best predicate to use. I tried where predicate but it didn't work.



Data:




"fname": "Mark",
"lname": "jhony",
"parcels": [

"parcelId": 123,
"parcelName: "asd",
"parcelItems": [

"itemId": 2,
"itemName": "perfume"
,

"itemId": 4,
"itemName": "soap"

]
,

"parcelId": 144,
"parcelName": "parcel2",
"parcelItems": [

"itemId": 2,
"itemName": "headphones"
,

"itemId": 4,
"itemName": "mouse"

]

]



HTML template:



<table mat-table [dataSource]="dataSource" matSort>
<ng-container matColumnDef="fname">
<th mat-header-cell *matHeaderCellDef mat-sort-header> Fname </th>
<td mat-cell *matCellDef="let element"> element.fname </td>
</ng-container>
<ng-container matColumnDef="lname">
<th mat-header-cell *matHeaderCellDef mat-sort-header> Lname </th>
<td mat-cell *matCellDef="let row"> row.lname </td>
</ng-container>
<ng-container matColumnDef="parcelid">
<th mat-header-cell *matHeaderCellDef mat-sort-header> Parcelid </th>
<td mat-cell *matCellDef="let element"> element.parcels[0].parcelId </td>

</ng-container>
<tr mat-header-row *matHeaderRowDef="displayedColumns"></tr>
<tr mat-row *matRowDef="let row;columns: displayedColumns;"></tr>
</table>


Here i can access the parcelId, like above element.parcels[0].parcelId. However, I want to make it repeat so the fname, lname and all the parcels of a particular user can be seen in the table










share|improve this question


























  • Is it intentional that your JSON data is missing some quotation marks?

    – Edric
    Oct 28 '18 at 15:27











  • sorry i edited the data and missed to add the quotation marks

    – Uahmed
    Oct 29 '18 at 10:16

















1















I am showing the data of my JSON file in the mat-table. The mat-table works fine in showing the rows but I have to show the data inside an array in a row. However, I don't know what would be the best predicate to use. I tried where predicate but it didn't work.



Data:




"fname": "Mark",
"lname": "jhony",
"parcels": [

"parcelId": 123,
"parcelName: "asd",
"parcelItems": [

"itemId": 2,
"itemName": "perfume"
,

"itemId": 4,
"itemName": "soap"

]
,

"parcelId": 144,
"parcelName": "parcel2",
"parcelItems": [

"itemId": 2,
"itemName": "headphones"
,

"itemId": 4,
"itemName": "mouse"

]

]



HTML template:



<table mat-table [dataSource]="dataSource" matSort>
<ng-container matColumnDef="fname">
<th mat-header-cell *matHeaderCellDef mat-sort-header> Fname </th>
<td mat-cell *matCellDef="let element"> element.fname </td>
</ng-container>
<ng-container matColumnDef="lname">
<th mat-header-cell *matHeaderCellDef mat-sort-header> Lname </th>
<td mat-cell *matCellDef="let row"> row.lname </td>
</ng-container>
<ng-container matColumnDef="parcelid">
<th mat-header-cell *matHeaderCellDef mat-sort-header> Parcelid </th>
<td mat-cell *matCellDef="let element"> element.parcels[0].parcelId </td>

</ng-container>
<tr mat-header-row *matHeaderRowDef="displayedColumns"></tr>
<tr mat-row *matRowDef="let row;columns: displayedColumns;"></tr>
</table>


Here i can access the parcelId, like above element.parcels[0].parcelId. However, I want to make it repeat so the fname, lname and all the parcels of a particular user can be seen in the table










share|improve this question


























  • Is it intentional that your JSON data is missing some quotation marks?

    – Edric
    Oct 28 '18 at 15:27











  • sorry i edited the data and missed to add the quotation marks

    – Uahmed
    Oct 29 '18 at 10:16













1












1








1








I am showing the data of my JSON file in the mat-table. The mat-table works fine in showing the rows but I have to show the data inside an array in a row. However, I don't know what would be the best predicate to use. I tried where predicate but it didn't work.



Data:




"fname": "Mark",
"lname": "jhony",
"parcels": [

"parcelId": 123,
"parcelName: "asd",
"parcelItems": [

"itemId": 2,
"itemName": "perfume"
,

"itemId": 4,
"itemName": "soap"

]
,

"parcelId": 144,
"parcelName": "parcel2",
"parcelItems": [

"itemId": 2,
"itemName": "headphones"
,

"itemId": 4,
"itemName": "mouse"

]

]



HTML template:



<table mat-table [dataSource]="dataSource" matSort>
<ng-container matColumnDef="fname">
<th mat-header-cell *matHeaderCellDef mat-sort-header> Fname </th>
<td mat-cell *matCellDef="let element"> element.fname </td>
</ng-container>
<ng-container matColumnDef="lname">
<th mat-header-cell *matHeaderCellDef mat-sort-header> Lname </th>
<td mat-cell *matCellDef="let row"> row.lname </td>
</ng-container>
<ng-container matColumnDef="parcelid">
<th mat-header-cell *matHeaderCellDef mat-sort-header> Parcelid </th>
<td mat-cell *matCellDef="let element"> element.parcels[0].parcelId </td>

</ng-container>
<tr mat-header-row *matHeaderRowDef="displayedColumns"></tr>
<tr mat-row *matRowDef="let row;columns: displayedColumns;"></tr>
</table>


Here i can access the parcelId, like above element.parcels[0].parcelId. However, I want to make it repeat so the fname, lname and all the parcels of a particular user can be seen in the table










share|improve this question
















I am showing the data of my JSON file in the mat-table. The mat-table works fine in showing the rows but I have to show the data inside an array in a row. However, I don't know what would be the best predicate to use. I tried where predicate but it didn't work.



Data:




"fname": "Mark",
"lname": "jhony",
"parcels": [

"parcelId": 123,
"parcelName: "asd",
"parcelItems": [

"itemId": 2,
"itemName": "perfume"
,

"itemId": 4,
"itemName": "soap"

]
,

"parcelId": 144,
"parcelName": "parcel2",
"parcelItems": [

"itemId": 2,
"itemName": "headphones"
,

"itemId": 4,
"itemName": "mouse"

]

]



HTML template:



<table mat-table [dataSource]="dataSource" matSort>
<ng-container matColumnDef="fname">
<th mat-header-cell *matHeaderCellDef mat-sort-header> Fname </th>
<td mat-cell *matCellDef="let element"> element.fname </td>
</ng-container>
<ng-container matColumnDef="lname">
<th mat-header-cell *matHeaderCellDef mat-sort-header> Lname </th>
<td mat-cell *matCellDef="let row"> row.lname </td>
</ng-container>
<ng-container matColumnDef="parcelid">
<th mat-header-cell *matHeaderCellDef mat-sort-header> Parcelid </th>
<td mat-cell *matCellDef="let element"> element.parcels[0].parcelId </td>

</ng-container>
<tr mat-header-row *matHeaderRowDef="displayedColumns"></tr>
<tr mat-row *matRowDef="let row;columns: displayedColumns;"></tr>
</table>


Here i can access the parcelId, like above element.parcels[0].parcelId. However, I want to make it repeat so the fname, lname and all the parcels of a particular user can be seen in the table







angular angular-material






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Oct 29 '18 at 10:16







Uahmed

















asked Oct 1 '18 at 14:36









UahmedUahmed

1,1964 gold badges20 silver badges39 bronze badges




1,1964 gold badges20 silver badges39 bronze badges















  • Is it intentional that your JSON data is missing some quotation marks?

    – Edric
    Oct 28 '18 at 15:27











  • sorry i edited the data and missed to add the quotation marks

    – Uahmed
    Oct 29 '18 at 10:16

















  • Is it intentional that your JSON data is missing some quotation marks?

    – Edric
    Oct 28 '18 at 15:27











  • sorry i edited the data and missed to add the quotation marks

    – Uahmed
    Oct 29 '18 at 10:16
















Is it intentional that your JSON data is missing some quotation marks?

– Edric
Oct 28 '18 at 15:27





Is it intentional that your JSON data is missing some quotation marks?

– Edric
Oct 28 '18 at 15:27













sorry i edited the data and missed to add the quotation marks

– Uahmed
Oct 29 '18 at 10:16





sorry i edited the data and missed to add the quotation marks

– Uahmed
Oct 29 '18 at 10:16












2 Answers
2






active

oldest

votes


















2
















If you know the number of parcels beforehand, and it is a fixed number, you could use ngFor in the HTML template and a for-loop when fetching data, before setting the data source, to fill in the correct number and names of displayed columns. If you don't have this information, you could always use ngFor in the template alone, listing all the data in a cell like this: https://stackblitz.com/edit/nested-table-data



 <ng-container matColumnDef="parcels">
<mat-header-cell *matHeaderCellDef> Parcels </mat-header-cell>
<mat-cell *matCellDef="let element">
<div class="parcels">
<ng-container *ngFor="let parcel of element.parcels">
<div class="parcel">
<ul>
<li>ID: parcel.parcelId</li>
<li>Name: parcel.parcelName</li>
</ul>
<ul>
<li *ngFor="let item of parcel.parcelItems">
<span>item.itemId: item.itemName</span>
</li>
</ul>
</div>
</ng-container>
</div>
</mat-cell>







share|improve this answer
































    1
















    The easiest way i found is to rearrange the array and make it accordingly to the table. This way i also able to achieve sorting and filter too in table .






    share|improve this answer

























    • My case is more complex, and object from AWS Cognito that includes arrays of arrays of objects, the user attributes and such. Mat Table reads the first level after I extract that level from the main object but not the lower ones. They have to be brought up the the first level as you suggest. Pain to code.

      – Preston
      Dec 11 '18 at 19:52












    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/4.0/"u003ecc by-sa 4.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );














    draft saved

    draft discarded
















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f52593450%2fangular-material-table-with-nested-data-source%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    2
















    If you know the number of parcels beforehand, and it is a fixed number, you could use ngFor in the HTML template and a for-loop when fetching data, before setting the data source, to fill in the correct number and names of displayed columns. If you don't have this information, you could always use ngFor in the template alone, listing all the data in a cell like this: https://stackblitz.com/edit/nested-table-data



     <ng-container matColumnDef="parcels">
    <mat-header-cell *matHeaderCellDef> Parcels </mat-header-cell>
    <mat-cell *matCellDef="let element">
    <div class="parcels">
    <ng-container *ngFor="let parcel of element.parcels">
    <div class="parcel">
    <ul>
    <li>ID: parcel.parcelId</li>
    <li>Name: parcel.parcelName</li>
    </ul>
    <ul>
    <li *ngFor="let item of parcel.parcelItems">
    <span>item.itemId: item.itemName</span>
    </li>
    </ul>
    </div>
    </ng-container>
    </div>
    </mat-cell>







    share|improve this answer





























      2
















      If you know the number of parcels beforehand, and it is a fixed number, you could use ngFor in the HTML template and a for-loop when fetching data, before setting the data source, to fill in the correct number and names of displayed columns. If you don't have this information, you could always use ngFor in the template alone, listing all the data in a cell like this: https://stackblitz.com/edit/nested-table-data



       <ng-container matColumnDef="parcels">
      <mat-header-cell *matHeaderCellDef> Parcels </mat-header-cell>
      <mat-cell *matCellDef="let element">
      <div class="parcels">
      <ng-container *ngFor="let parcel of element.parcels">
      <div class="parcel">
      <ul>
      <li>ID: parcel.parcelId</li>
      <li>Name: parcel.parcelName</li>
      </ul>
      <ul>
      <li *ngFor="let item of parcel.parcelItems">
      <span>item.itemId: item.itemName</span>
      </li>
      </ul>
      </div>
      </ng-container>
      </div>
      </mat-cell>







      share|improve this answer



























        2














        2










        2









        If you know the number of parcels beforehand, and it is a fixed number, you could use ngFor in the HTML template and a for-loop when fetching data, before setting the data source, to fill in the correct number and names of displayed columns. If you don't have this information, you could always use ngFor in the template alone, listing all the data in a cell like this: https://stackblitz.com/edit/nested-table-data



         <ng-container matColumnDef="parcels">
        <mat-header-cell *matHeaderCellDef> Parcels </mat-header-cell>
        <mat-cell *matCellDef="let element">
        <div class="parcels">
        <ng-container *ngFor="let parcel of element.parcels">
        <div class="parcel">
        <ul>
        <li>ID: parcel.parcelId</li>
        <li>Name: parcel.parcelName</li>
        </ul>
        <ul>
        <li *ngFor="let item of parcel.parcelItems">
        <span>item.itemId: item.itemName</span>
        </li>
        </ul>
        </div>
        </ng-container>
        </div>
        </mat-cell>







        share|improve this answer













        If you know the number of parcels beforehand, and it is a fixed number, you could use ngFor in the HTML template and a for-loop when fetching data, before setting the data source, to fill in the correct number and names of displayed columns. If you don't have this information, you could always use ngFor in the template alone, listing all the data in a cell like this: https://stackblitz.com/edit/nested-table-data



         <ng-container matColumnDef="parcels">
        <mat-header-cell *matHeaderCellDef> Parcels </mat-header-cell>
        <mat-cell *matCellDef="let element">
        <div class="parcels">
        <ng-container *ngFor="let parcel of element.parcels">
        <div class="parcel">
        <ul>
        <li>ID: parcel.parcelId</li>
        <li>Name: parcel.parcelName</li>
        </ul>
        <ul>
        <li *ngFor="let item of parcel.parcelItems">
        <span>item.itemId: item.itemName</span>
        </li>
        </ul>
        </div>
        </ng-container>
        </div>
        </mat-cell>








        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Apr 18 at 8:40









        Lars RødalLars Rødal

        3663 silver badges12 bronze badges




        3663 silver badges12 bronze badges


























            1
















            The easiest way i found is to rearrange the array and make it accordingly to the table. This way i also able to achieve sorting and filter too in table .






            share|improve this answer

























            • My case is more complex, and object from AWS Cognito that includes arrays of arrays of objects, the user attributes and such. Mat Table reads the first level after I extract that level from the main object but not the lower ones. They have to be brought up the the first level as you suggest. Pain to code.

              – Preston
              Dec 11 '18 at 19:52















            1
















            The easiest way i found is to rearrange the array and make it accordingly to the table. This way i also able to achieve sorting and filter too in table .






            share|improve this answer

























            • My case is more complex, and object from AWS Cognito that includes arrays of arrays of objects, the user attributes and such. Mat Table reads the first level after I extract that level from the main object but not the lower ones. They have to be brought up the the first level as you suggest. Pain to code.

              – Preston
              Dec 11 '18 at 19:52













            1














            1










            1









            The easiest way i found is to rearrange the array and make it accordingly to the table. This way i also able to achieve sorting and filter too in table .






            share|improve this answer













            The easiest way i found is to rearrange the array and make it accordingly to the table. This way i also able to achieve sorting and filter too in table .







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Oct 2 '18 at 14:04









            UahmedUahmed

            1,1964 gold badges20 silver badges39 bronze badges




            1,1964 gold badges20 silver badges39 bronze badges















            • My case is more complex, and object from AWS Cognito that includes arrays of arrays of objects, the user attributes and such. Mat Table reads the first level after I extract that level from the main object but not the lower ones. They have to be brought up the the first level as you suggest. Pain to code.

              – Preston
              Dec 11 '18 at 19:52

















            • My case is more complex, and object from AWS Cognito that includes arrays of arrays of objects, the user attributes and such. Mat Table reads the first level after I extract that level from the main object but not the lower ones. They have to be brought up the the first level as you suggest. Pain to code.

              – Preston
              Dec 11 '18 at 19:52
















            My case is more complex, and object from AWS Cognito that includes arrays of arrays of objects, the user attributes and such. Mat Table reads the first level after I extract that level from the main object but not the lower ones. They have to be brought up the the first level as you suggest. Pain to code.

            – Preston
            Dec 11 '18 at 19:52





            My case is more complex, and object from AWS Cognito that includes arrays of arrays of objects, the user attributes and such. Mat Table reads the first level after I extract that level from the main object but not the lower ones. They have to be brought up the the first level as you suggest. Pain to code.

            – Preston
            Dec 11 '18 at 19:52


















            draft saved

            draft discarded















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f52593450%2fangular-material-table-with-nested-data-source%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

            SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

            은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현