How to feed data to mat-cell based off of data from a different mat-cell
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
add a comment |
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
add a comment |
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
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
angular5 mat-table
edited Nov 13 '18 at 9:42
JupiterFullMean
asked Nov 13 '18 at 8:35
JupiterFullMeanJupiterFullMean
284
284
add a comment |
add a comment |
3 Answers
3
active
oldest
votes
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>
add a comment |
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>
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
|
show 2 more comments
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>
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
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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>
add a comment |
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>
add a comment |
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>
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>
answered Nov 13 '18 at 9:33
HarisHaris
679
679
add a comment |
add a comment |
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>
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
|
show 2 more comments
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>
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
|
show 2 more comments
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>
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>
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
|
show 2 more comments
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
|
show 2 more comments
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>
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
add a comment |
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>
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
add a comment |
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>
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>
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
add a comment |
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
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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