How to feed data to mat-cell based off of data from a different mat-cell












0














I have a mat-table that renders data dynamically like this:



<ng-container matColumnDef="type">
<mat-header-cell *matHeaderCellDef> No. </mat-header-cell>
<mat-cell *matCellDef="let element"> {{element.type}} </mat-cell>
</ng-container>

<ng-container matColumnDef="count">
<mat-header-cell *matHeaderCellDef> Count </mat-header-cell>
<mat-cell *matCellDef="let element"> {{element.count}} </mat-cell>
</ng-container>


I dont have count in the model i am querying the number of items from the back end and returning the count by grouping how many each type has using aggregate function and $group. the types (electronics, households...) are in the collection
..



[{_id: objectId type: electronics}
{_id: objectId type: households}
]


after aggregate and grouping query i get this array back



[
{type: electronics count: 139},
{type: households count: 400},
...

]


I want to add a count column that counts the number of different items where electronics will be its own row and return 139 in the count column and household its own row and return 400



I am successfully in logging the data returned from the backend but how do i display it on mat table.



Using angular 5 material how do I iterate through the mat-cell and grab each type (electronic, households from a different cell) and display the count for that type on its respective row? any suggestion would be appreciated!










share|improve this question





























    0














    I have a mat-table that renders data dynamically like this:



    <ng-container matColumnDef="type">
    <mat-header-cell *matHeaderCellDef> No. </mat-header-cell>
    <mat-cell *matCellDef="let element"> {{element.type}} </mat-cell>
    </ng-container>

    <ng-container matColumnDef="count">
    <mat-header-cell *matHeaderCellDef> Count </mat-header-cell>
    <mat-cell *matCellDef="let element"> {{element.count}} </mat-cell>
    </ng-container>


    I dont have count in the model i am querying the number of items from the back end and returning the count by grouping how many each type has using aggregate function and $group. the types (electronics, households...) are in the collection
    ..



    [{_id: objectId type: electronics}
    {_id: objectId type: households}
    ]


    after aggregate and grouping query i get this array back



    [
    {type: electronics count: 139},
    {type: households count: 400},
    ...

    ]


    I want to add a count column that counts the number of different items where electronics will be its own row and return 139 in the count column and household its own row and return 400



    I am successfully in logging the data returned from the backend but how do i display it on mat table.



    Using angular 5 material how do I iterate through the mat-cell and grab each type (electronic, households from a different cell) and display the count for that type on its respective row? any suggestion would be appreciated!










    share|improve this question



























      0












      0








      0







      I have a mat-table that renders data dynamically like this:



      <ng-container matColumnDef="type">
      <mat-header-cell *matHeaderCellDef> No. </mat-header-cell>
      <mat-cell *matCellDef="let element"> {{element.type}} </mat-cell>
      </ng-container>

      <ng-container matColumnDef="count">
      <mat-header-cell *matHeaderCellDef> Count </mat-header-cell>
      <mat-cell *matCellDef="let element"> {{element.count}} </mat-cell>
      </ng-container>


      I dont have count in the model i am querying the number of items from the back end and returning the count by grouping how many each type has using aggregate function and $group. the types (electronics, households...) are in the collection
      ..



      [{_id: objectId type: electronics}
      {_id: objectId type: households}
      ]


      after aggregate and grouping query i get this array back



      [
      {type: electronics count: 139},
      {type: households count: 400},
      ...

      ]


      I want to add a count column that counts the number of different items where electronics will be its own row and return 139 in the count column and household its own row and return 400



      I am successfully in logging the data returned from the backend but how do i display it on mat table.



      Using angular 5 material how do I iterate through the mat-cell and grab each type (electronic, households from a different cell) and display the count for that type on its respective row? any suggestion would be appreciated!










      share|improve this question















      I have a mat-table that renders data dynamically like this:



      <ng-container matColumnDef="type">
      <mat-header-cell *matHeaderCellDef> No. </mat-header-cell>
      <mat-cell *matCellDef="let element"> {{element.type}} </mat-cell>
      </ng-container>

      <ng-container matColumnDef="count">
      <mat-header-cell *matHeaderCellDef> Count </mat-header-cell>
      <mat-cell *matCellDef="let element"> {{element.count}} </mat-cell>
      </ng-container>


      I dont have count in the model i am querying the number of items from the back end and returning the count by grouping how many each type has using aggregate function and $group. the types (electronics, households...) are in the collection
      ..



      [{_id: objectId type: electronics}
      {_id: objectId type: households}
      ]


      after aggregate and grouping query i get this array back



      [
      {type: electronics count: 139},
      {type: households count: 400},
      ...

      ]


      I want to add a count column that counts the number of different items where electronics will be its own row and return 139 in the count column and household its own row and return 400



      I am successfully in logging the data returned from the backend but how do i display it on mat table.



      Using angular 5 material how do I iterate through the mat-cell and grab each type (electronic, households from a different cell) and display the count for that type on its respective row? any suggestion would be appreciated!







      angular5 mat-table






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 13 '18 at 9:42







      JupiterFullMean

















      asked Nov 13 '18 at 8:35









      JupiterFullMeanJupiterFullMean

      284




      284
























          3 Answers
          3






          active

          oldest

          votes


















          0














          If you have this array on your component and want to show this on table.



          let mydata = [
          {type: electronics count: 139},
          {type: households count: 400},
          ...
          ]


          and in your template you have



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

          <ng-container matColumnDef="items">
          <mat-header-cell *matHeaderCellDef> No. </mat-header-cell>
          <mat-cell *matCellDef="let element"> {{element.type}} </mat-cell>
          </ng-container>

          <ng-container matColumnDef="count">
          <mat-header-cell *matHeaderCellDef> Count </mat-header-cell>
          <mat-cell *matCellDef="let element"> {{element.count}} </mat-cell>
          </ng-container>

          <tr mat-header-row *matHeaderRowDef="displayedColumns; sticky: true"></tr>
          <tr mat-row *matRowDef="let row; columns: ['type','count'];">
          </tr>
          </table>





          share|improve this answer





























            0














            you can save your data returning into your component and then you can write a function to get a count of given item from the component like.



            component



            import { Component } from '@angular/core';



            @Component({
            templateUrl: './demo.component.html',
            styleUrls: ['./demo.component.css']
            })
            export class DemoComponent {

            result : any;
            constructor() { }

            getCount(itemName){
            let count = 0;
            for(var i = 0; i < result.length; i++){
            if(result[i].itemName===itemName){
            count++;
            }
            }
            return count;
            }
            }


            on Table you can have



            <ng-container matColumnDef="items">
            <mat-header-cell *matHeaderCellDef> No. </mat-header-cell>
            <mat-cell *matCellDef="let element"> {{element.items}} </mat-cell>
            </ng-container>

            <ng-container matColumnDef="count">
            <mat-header-cell *matHeaderCellDef> Count </mat-header-cell>
            <mat-cell *matCellDef="let element"> {{getCount(element.itemName)}} </mat-cell>
            </ng-container>





            share|improve this answer























            • thanks for reply..I already have the count being returned from the backend using aggregate and $group and service layer that gets that count..so i dont need to iterate from the front end i just need to display count on its own column
              – JupiterFullMean
              Nov 13 '18 at 9:04










            • OK, have you tried to add in display columns? like this <tr mat-header-row *matHeaderRowDef="displayedColumns; sticky: true"></tr> <tr mat-row *matRowDef="let row; columns: ['element','count'];"> </tr>
              – Haris
              Nov 13 '18 at 9:06










            • Actually this is how my json looks like [ {type: electronics count: 139}, {type: households count: 400}, ... ]
              – JupiterFullMean
              Nov 13 '18 at 9:17










            • so, you want to to show this json [ {type: electronics count: 139}, {type: households count: 400}, ... ] as in the table right?
              – Haris
              Nov 13 '18 at 9:20












            • correct..ive modified added details in the question its a bit tricky because count doesnt have a model or schema its an aggregate function that groups a collection and returns count of that specific type..
              – JupiterFullMean
              Nov 13 '18 at 9:24



















            0














            ok. you have two different arrays



            export interface myData {
            elements: any;
            }
            @Component({
            templateUrl: './demo.component.html',
            styleUrls: ['./demo.component.css']
            })
            export class DemoComponent {

            displayedColumns: string = ['type','count'];
            dataSource : myData = ;
            arrayThatcontainsCount = ;

            someFunction(){
            this.someService.get().then((result: any) =>{
            this.dataSource = result.data;
            }
            }

            someFunction(){
            //getting count array from api and setting array "arrayThatcontainsCount"
            }

            getCountOfElement(type){
            let elem = this.arrayThatcontainsCount.find((r)=> r.type == type);
            return elem.count;
            }
            }


            and in html



            <ng-container matColumnDef="items">
            <mat-header-cell *matHeaderCellDef> No. </mat-header-cell>
            <mat-cell *matCellDef="let element"> {{element.type}} </mat-cell>
            </ng-container>

            <ng-container matColumnDef="count">
            <mat-header-cell *matHeaderCellDef> Count </mat-header-cell>
            <mat-cell *matCellDef="let element"> {{getCountOfElement(element.type)}} </mat-cell>
            </ng-container>





            share|improve this answer























            • Currently I can get the count for one specific thing "electronic" " but it repeats the count for electronics on all rows. its not differentiating between electronics and household mat-cell and print out the count on its respective type...will update soon
              – JupiterFullMean
              Nov 13 '18 at 12:06











            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/3.0/"u003ecc by-sa 3.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%2f53276855%2fhow-to-feed-data-to-mat-cell-based-off-of-data-from-a-different-mat-cell%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            3 Answers
            3






            active

            oldest

            votes








            3 Answers
            3






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            If you have this array on your component and want to show this on table.



            let mydata = [
            {type: electronics count: 139},
            {type: households count: 400},
            ...
            ]


            and in your template you have



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

            <ng-container matColumnDef="items">
            <mat-header-cell *matHeaderCellDef> No. </mat-header-cell>
            <mat-cell *matCellDef="let element"> {{element.type}} </mat-cell>
            </ng-container>

            <ng-container matColumnDef="count">
            <mat-header-cell *matHeaderCellDef> Count </mat-header-cell>
            <mat-cell *matCellDef="let element"> {{element.count}} </mat-cell>
            </ng-container>

            <tr mat-header-row *matHeaderRowDef="displayedColumns; sticky: true"></tr>
            <tr mat-row *matRowDef="let row; columns: ['type','count'];">
            </tr>
            </table>





            share|improve this answer


























              0














              If you have this array on your component and want to show this on table.



              let mydata = [
              {type: electronics count: 139},
              {type: households count: 400},
              ...
              ]


              and in your template you have



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

              <ng-container matColumnDef="items">
              <mat-header-cell *matHeaderCellDef> No. </mat-header-cell>
              <mat-cell *matCellDef="let element"> {{element.type}} </mat-cell>
              </ng-container>

              <ng-container matColumnDef="count">
              <mat-header-cell *matHeaderCellDef> Count </mat-header-cell>
              <mat-cell *matCellDef="let element"> {{element.count}} </mat-cell>
              </ng-container>

              <tr mat-header-row *matHeaderRowDef="displayedColumns; sticky: true"></tr>
              <tr mat-row *matRowDef="let row; columns: ['type','count'];">
              </tr>
              </table>





              share|improve this answer
























                0












                0








                0






                If you have this array on your component and want to show this on table.



                let mydata = [
                {type: electronics count: 139},
                {type: households count: 400},
                ...
                ]


                and in your template you have



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

                <ng-container matColumnDef="items">
                <mat-header-cell *matHeaderCellDef> No. </mat-header-cell>
                <mat-cell *matCellDef="let element"> {{element.type}} </mat-cell>
                </ng-container>

                <ng-container matColumnDef="count">
                <mat-header-cell *matHeaderCellDef> Count </mat-header-cell>
                <mat-cell *matCellDef="let element"> {{element.count}} </mat-cell>
                </ng-container>

                <tr mat-header-row *matHeaderRowDef="displayedColumns; sticky: true"></tr>
                <tr mat-row *matRowDef="let row; columns: ['type','count'];">
                </tr>
                </table>





                share|improve this answer












                If you have this array on your component and want to show this on table.



                let mydata = [
                {type: electronics count: 139},
                {type: households count: 400},
                ...
                ]


                and in your template you have



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

                <ng-container matColumnDef="items">
                <mat-header-cell *matHeaderCellDef> No. </mat-header-cell>
                <mat-cell *matCellDef="let element"> {{element.type}} </mat-cell>
                </ng-container>

                <ng-container matColumnDef="count">
                <mat-header-cell *matHeaderCellDef> Count </mat-header-cell>
                <mat-cell *matCellDef="let element"> {{element.count}} </mat-cell>
                </ng-container>

                <tr mat-header-row *matHeaderRowDef="displayedColumns; sticky: true"></tr>
                <tr mat-row *matRowDef="let row; columns: ['type','count'];">
                </tr>
                </table>






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 13 '18 at 9:33









                HarisHaris

                679




                679

























                    0














                    you can save your data returning into your component and then you can write a function to get a count of given item from the component like.



                    component



                    import { Component } from '@angular/core';



                    @Component({
                    templateUrl: './demo.component.html',
                    styleUrls: ['./demo.component.css']
                    })
                    export class DemoComponent {

                    result : any;
                    constructor() { }

                    getCount(itemName){
                    let count = 0;
                    for(var i = 0; i < result.length; i++){
                    if(result[i].itemName===itemName){
                    count++;
                    }
                    }
                    return count;
                    }
                    }


                    on Table you can have



                    <ng-container matColumnDef="items">
                    <mat-header-cell *matHeaderCellDef> No. </mat-header-cell>
                    <mat-cell *matCellDef="let element"> {{element.items}} </mat-cell>
                    </ng-container>

                    <ng-container matColumnDef="count">
                    <mat-header-cell *matHeaderCellDef> Count </mat-header-cell>
                    <mat-cell *matCellDef="let element"> {{getCount(element.itemName)}} </mat-cell>
                    </ng-container>





                    share|improve this answer























                    • thanks for reply..I already have the count being returned from the backend using aggregate and $group and service layer that gets that count..so i dont need to iterate from the front end i just need to display count on its own column
                      – JupiterFullMean
                      Nov 13 '18 at 9:04










                    • OK, have you tried to add in display columns? like this <tr mat-header-row *matHeaderRowDef="displayedColumns; sticky: true"></tr> <tr mat-row *matRowDef="let row; columns: ['element','count'];"> </tr>
                      – Haris
                      Nov 13 '18 at 9:06










                    • Actually this is how my json looks like [ {type: electronics count: 139}, {type: households count: 400}, ... ]
                      – JupiterFullMean
                      Nov 13 '18 at 9:17










                    • so, you want to to show this json [ {type: electronics count: 139}, {type: households count: 400}, ... ] as in the table right?
                      – Haris
                      Nov 13 '18 at 9:20












                    • correct..ive modified added details in the question its a bit tricky because count doesnt have a model or schema its an aggregate function that groups a collection and returns count of that specific type..
                      – JupiterFullMean
                      Nov 13 '18 at 9:24
















                    0














                    you can save your data returning into your component and then you can write a function to get a count of given item from the component like.



                    component



                    import { Component } from '@angular/core';



                    @Component({
                    templateUrl: './demo.component.html',
                    styleUrls: ['./demo.component.css']
                    })
                    export class DemoComponent {

                    result : any;
                    constructor() { }

                    getCount(itemName){
                    let count = 0;
                    for(var i = 0; i < result.length; i++){
                    if(result[i].itemName===itemName){
                    count++;
                    }
                    }
                    return count;
                    }
                    }


                    on Table you can have



                    <ng-container matColumnDef="items">
                    <mat-header-cell *matHeaderCellDef> No. </mat-header-cell>
                    <mat-cell *matCellDef="let element"> {{element.items}} </mat-cell>
                    </ng-container>

                    <ng-container matColumnDef="count">
                    <mat-header-cell *matHeaderCellDef> Count </mat-header-cell>
                    <mat-cell *matCellDef="let element"> {{getCount(element.itemName)}} </mat-cell>
                    </ng-container>





                    share|improve this answer























                    • thanks for reply..I already have the count being returned from the backend using aggregate and $group and service layer that gets that count..so i dont need to iterate from the front end i just need to display count on its own column
                      – JupiterFullMean
                      Nov 13 '18 at 9:04










                    • OK, have you tried to add in display columns? like this <tr mat-header-row *matHeaderRowDef="displayedColumns; sticky: true"></tr> <tr mat-row *matRowDef="let row; columns: ['element','count'];"> </tr>
                      – Haris
                      Nov 13 '18 at 9:06










                    • Actually this is how my json looks like [ {type: electronics count: 139}, {type: households count: 400}, ... ]
                      – JupiterFullMean
                      Nov 13 '18 at 9:17










                    • so, you want to to show this json [ {type: electronics count: 139}, {type: households count: 400}, ... ] as in the table right?
                      – Haris
                      Nov 13 '18 at 9:20












                    • correct..ive modified added details in the question its a bit tricky because count doesnt have a model or schema its an aggregate function that groups a collection and returns count of that specific type..
                      – JupiterFullMean
                      Nov 13 '18 at 9:24














                    0












                    0








                    0






                    you can save your data returning into your component and then you can write a function to get a count of given item from the component like.



                    component



                    import { Component } from '@angular/core';



                    @Component({
                    templateUrl: './demo.component.html',
                    styleUrls: ['./demo.component.css']
                    })
                    export class DemoComponent {

                    result : any;
                    constructor() { }

                    getCount(itemName){
                    let count = 0;
                    for(var i = 0; i < result.length; i++){
                    if(result[i].itemName===itemName){
                    count++;
                    }
                    }
                    return count;
                    }
                    }


                    on Table you can have



                    <ng-container matColumnDef="items">
                    <mat-header-cell *matHeaderCellDef> No. </mat-header-cell>
                    <mat-cell *matCellDef="let element"> {{element.items}} </mat-cell>
                    </ng-container>

                    <ng-container matColumnDef="count">
                    <mat-header-cell *matHeaderCellDef> Count </mat-header-cell>
                    <mat-cell *matCellDef="let element"> {{getCount(element.itemName)}} </mat-cell>
                    </ng-container>





                    share|improve this answer














                    you can save your data returning into your component and then you can write a function to get a count of given item from the component like.



                    component



                    import { Component } from '@angular/core';



                    @Component({
                    templateUrl: './demo.component.html',
                    styleUrls: ['./demo.component.css']
                    })
                    export class DemoComponent {

                    result : any;
                    constructor() { }

                    getCount(itemName){
                    let count = 0;
                    for(var i = 0; i < result.length; i++){
                    if(result[i].itemName===itemName){
                    count++;
                    }
                    }
                    return count;
                    }
                    }


                    on Table you can have



                    <ng-container matColumnDef="items">
                    <mat-header-cell *matHeaderCellDef> No. </mat-header-cell>
                    <mat-cell *matCellDef="let element"> {{element.items}} </mat-cell>
                    </ng-container>

                    <ng-container matColumnDef="count">
                    <mat-header-cell *matHeaderCellDef> Count </mat-header-cell>
                    <mat-cell *matCellDef="let element"> {{getCount(element.itemName)}} </mat-cell>
                    </ng-container>






                    share|improve this answer














                    share|improve this answer



                    share|improve this answer








                    edited Nov 13 '18 at 10:04

























                    answered Nov 13 '18 at 8:45









                    HarisHaris

                    679




                    679












                    • thanks for reply..I already have the count being returned from the backend using aggregate and $group and service layer that gets that count..so i dont need to iterate from the front end i just need to display count on its own column
                      – JupiterFullMean
                      Nov 13 '18 at 9:04










                    • OK, have you tried to add in display columns? like this <tr mat-header-row *matHeaderRowDef="displayedColumns; sticky: true"></tr> <tr mat-row *matRowDef="let row; columns: ['element','count'];"> </tr>
                      – Haris
                      Nov 13 '18 at 9:06










                    • Actually this is how my json looks like [ {type: electronics count: 139}, {type: households count: 400}, ... ]
                      – JupiterFullMean
                      Nov 13 '18 at 9:17










                    • so, you want to to show this json [ {type: electronics count: 139}, {type: households count: 400}, ... ] as in the table right?
                      – Haris
                      Nov 13 '18 at 9:20












                    • correct..ive modified added details in the question its a bit tricky because count doesnt have a model or schema its an aggregate function that groups a collection and returns count of that specific type..
                      – JupiterFullMean
                      Nov 13 '18 at 9:24


















                    • thanks for reply..I already have the count being returned from the backend using aggregate and $group and service layer that gets that count..so i dont need to iterate from the front end i just need to display count on its own column
                      – JupiterFullMean
                      Nov 13 '18 at 9:04










                    • OK, have you tried to add in display columns? like this <tr mat-header-row *matHeaderRowDef="displayedColumns; sticky: true"></tr> <tr mat-row *matRowDef="let row; columns: ['element','count'];"> </tr>
                      – Haris
                      Nov 13 '18 at 9:06










                    • Actually this is how my json looks like [ {type: electronics count: 139}, {type: households count: 400}, ... ]
                      – JupiterFullMean
                      Nov 13 '18 at 9:17










                    • so, you want to to show this json [ {type: electronics count: 139}, {type: households count: 400}, ... ] as in the table right?
                      – Haris
                      Nov 13 '18 at 9:20












                    • correct..ive modified added details in the question its a bit tricky because count doesnt have a model or schema its an aggregate function that groups a collection and returns count of that specific type..
                      – JupiterFullMean
                      Nov 13 '18 at 9:24
















                    thanks for reply..I already have the count being returned from the backend using aggregate and $group and service layer that gets that count..so i dont need to iterate from the front end i just need to display count on its own column
                    – JupiterFullMean
                    Nov 13 '18 at 9:04




                    thanks for reply..I already have the count being returned from the backend using aggregate and $group and service layer that gets that count..so i dont need to iterate from the front end i just need to display count on its own column
                    – JupiterFullMean
                    Nov 13 '18 at 9:04












                    OK, have you tried to add in display columns? like this <tr mat-header-row *matHeaderRowDef="displayedColumns; sticky: true"></tr> <tr mat-row *matRowDef="let row; columns: ['element','count'];"> </tr>
                    – Haris
                    Nov 13 '18 at 9:06




                    OK, have you tried to add in display columns? like this <tr mat-header-row *matHeaderRowDef="displayedColumns; sticky: true"></tr> <tr mat-row *matRowDef="let row; columns: ['element','count'];"> </tr>
                    – Haris
                    Nov 13 '18 at 9:06












                    Actually this is how my json looks like [ {type: electronics count: 139}, {type: households count: 400}, ... ]
                    – JupiterFullMean
                    Nov 13 '18 at 9:17




                    Actually this is how my json looks like [ {type: electronics count: 139}, {type: households count: 400}, ... ]
                    – JupiterFullMean
                    Nov 13 '18 at 9:17












                    so, you want to to show this json [ {type: electronics count: 139}, {type: households count: 400}, ... ] as in the table right?
                    – Haris
                    Nov 13 '18 at 9:20






                    so, you want to to show this json [ {type: electronics count: 139}, {type: households count: 400}, ... ] as in the table right?
                    – Haris
                    Nov 13 '18 at 9:20














                    correct..ive modified added details in the question its a bit tricky because count doesnt have a model or schema its an aggregate function that groups a collection and returns count of that specific type..
                    – JupiterFullMean
                    Nov 13 '18 at 9:24




                    correct..ive modified added details in the question its a bit tricky because count doesnt have a model or schema its an aggregate function that groups a collection and returns count of that specific type..
                    – JupiterFullMean
                    Nov 13 '18 at 9:24











                    0














                    ok. you have two different arrays



                    export interface myData {
                    elements: any;
                    }
                    @Component({
                    templateUrl: './demo.component.html',
                    styleUrls: ['./demo.component.css']
                    })
                    export class DemoComponent {

                    displayedColumns: string = ['type','count'];
                    dataSource : myData = ;
                    arrayThatcontainsCount = ;

                    someFunction(){
                    this.someService.get().then((result: any) =>{
                    this.dataSource = result.data;
                    }
                    }

                    someFunction(){
                    //getting count array from api and setting array "arrayThatcontainsCount"
                    }

                    getCountOfElement(type){
                    let elem = this.arrayThatcontainsCount.find((r)=> r.type == type);
                    return elem.count;
                    }
                    }


                    and in html



                    <ng-container matColumnDef="items">
                    <mat-header-cell *matHeaderCellDef> No. </mat-header-cell>
                    <mat-cell *matCellDef="let element"> {{element.type}} </mat-cell>
                    </ng-container>

                    <ng-container matColumnDef="count">
                    <mat-header-cell *matHeaderCellDef> Count </mat-header-cell>
                    <mat-cell *matCellDef="let element"> {{getCountOfElement(element.type)}} </mat-cell>
                    </ng-container>





                    share|improve this answer























                    • Currently I can get the count for one specific thing "electronic" " but it repeats the count for electronics on all rows. its not differentiating between electronics and household mat-cell and print out the count on its respective type...will update soon
                      – JupiterFullMean
                      Nov 13 '18 at 12:06
















                    0














                    ok. you have two different arrays



                    export interface myData {
                    elements: any;
                    }
                    @Component({
                    templateUrl: './demo.component.html',
                    styleUrls: ['./demo.component.css']
                    })
                    export class DemoComponent {

                    displayedColumns: string = ['type','count'];
                    dataSource : myData = ;
                    arrayThatcontainsCount = ;

                    someFunction(){
                    this.someService.get().then((result: any) =>{
                    this.dataSource = result.data;
                    }
                    }

                    someFunction(){
                    //getting count array from api and setting array "arrayThatcontainsCount"
                    }

                    getCountOfElement(type){
                    let elem = this.arrayThatcontainsCount.find((r)=> r.type == type);
                    return elem.count;
                    }
                    }


                    and in html



                    <ng-container matColumnDef="items">
                    <mat-header-cell *matHeaderCellDef> No. </mat-header-cell>
                    <mat-cell *matCellDef="let element"> {{element.type}} </mat-cell>
                    </ng-container>

                    <ng-container matColumnDef="count">
                    <mat-header-cell *matHeaderCellDef> Count </mat-header-cell>
                    <mat-cell *matCellDef="let element"> {{getCountOfElement(element.type)}} </mat-cell>
                    </ng-container>





                    share|improve this answer























                    • Currently I can get the count for one specific thing "electronic" " but it repeats the count for electronics on all rows. its not differentiating between electronics and household mat-cell and print out the count on its respective type...will update soon
                      – JupiterFullMean
                      Nov 13 '18 at 12:06














                    0












                    0








                    0






                    ok. you have two different arrays



                    export interface myData {
                    elements: any;
                    }
                    @Component({
                    templateUrl: './demo.component.html',
                    styleUrls: ['./demo.component.css']
                    })
                    export class DemoComponent {

                    displayedColumns: string = ['type','count'];
                    dataSource : myData = ;
                    arrayThatcontainsCount = ;

                    someFunction(){
                    this.someService.get().then((result: any) =>{
                    this.dataSource = result.data;
                    }
                    }

                    someFunction(){
                    //getting count array from api and setting array "arrayThatcontainsCount"
                    }

                    getCountOfElement(type){
                    let elem = this.arrayThatcontainsCount.find((r)=> r.type == type);
                    return elem.count;
                    }
                    }


                    and in html



                    <ng-container matColumnDef="items">
                    <mat-header-cell *matHeaderCellDef> No. </mat-header-cell>
                    <mat-cell *matCellDef="let element"> {{element.type}} </mat-cell>
                    </ng-container>

                    <ng-container matColumnDef="count">
                    <mat-header-cell *matHeaderCellDef> Count </mat-header-cell>
                    <mat-cell *matCellDef="let element"> {{getCountOfElement(element.type)}} </mat-cell>
                    </ng-container>





                    share|improve this answer














                    ok. you have two different arrays



                    export interface myData {
                    elements: any;
                    }
                    @Component({
                    templateUrl: './demo.component.html',
                    styleUrls: ['./demo.component.css']
                    })
                    export class DemoComponent {

                    displayedColumns: string = ['type','count'];
                    dataSource : myData = ;
                    arrayThatcontainsCount = ;

                    someFunction(){
                    this.someService.get().then((result: any) =>{
                    this.dataSource = result.data;
                    }
                    }

                    someFunction(){
                    //getting count array from api and setting array "arrayThatcontainsCount"
                    }

                    getCountOfElement(type){
                    let elem = this.arrayThatcontainsCount.find((r)=> r.type == type);
                    return elem.count;
                    }
                    }


                    and in html



                    <ng-container matColumnDef="items">
                    <mat-header-cell *matHeaderCellDef> No. </mat-header-cell>
                    <mat-cell *matCellDef="let element"> {{element.type}} </mat-cell>
                    </ng-container>

                    <ng-container matColumnDef="count">
                    <mat-header-cell *matHeaderCellDef> Count </mat-header-cell>
                    <mat-cell *matCellDef="let element"> {{getCountOfElement(element.type)}} </mat-cell>
                    </ng-container>






                    share|improve this answer














                    share|improve this answer



                    share|improve this answer








                    edited Nov 13 '18 at 11:10

























                    answered Nov 13 '18 at 9:42









                    HarisHaris

                    679




                    679












                    • Currently I can get the count for one specific thing "electronic" " but it repeats the count for electronics on all rows. its not differentiating between electronics and household mat-cell and print out the count on its respective type...will update soon
                      – JupiterFullMean
                      Nov 13 '18 at 12:06


















                    • Currently I can get the count for one specific thing "electronic" " but it repeats the count for electronics on all rows. its not differentiating between electronics and household mat-cell and print out the count on its respective type...will update soon
                      – JupiterFullMean
                      Nov 13 '18 at 12:06
















                    Currently I can get the count for one specific thing "electronic" " but it repeats the count for electronics on all rows. its not differentiating between electronics and household mat-cell and print out the count on its respective type...will update soon
                    – JupiterFullMean
                    Nov 13 '18 at 12:06




                    Currently I can get the count for one specific thing "electronic" " but it repeats the count for electronics on all rows. its not differentiating between electronics and household mat-cell and print out the count on its respective type...will update soon
                    – JupiterFullMean
                    Nov 13 '18 at 12:06


















                    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.





                    Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                    Please pay close attention to the following guidance:


                    • 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%2f53276855%2fhow-to-feed-data-to-mat-cell-based-off-of-data-from-a-different-mat-cell%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

                    List item for chat from Array inside array React Native

                    Thiostrepton

                    Caerphilly