I have Following Json:
{
"FunctionIs": [{
"id": 1,
"name": "Test",
"Type": "A"
}, {
"id": 2,
"name": "Test2",
"Type": "A"
},{
"id": 3,
"name": "Test3",
"Type": "A"
},{
"id": 4,
"name": "Test4",
"Type": "A"
},{
"id": 5,
"name": "Test5",
"Type": "B"
},{
"id": 6,
"name": "Test6",
"Type": "B"
},{
"id": 7,
"name": "Test7",
"Type": "C"
},{
"id": 8,
"name": "Test8",
"Type": "C"
},]
}
I am populating these values through ng-repeat in my html:
<tr ng-repeat="businessdata in userObj.businessJson">
<td id="idIs">{{businessdata.id}}</td>
<td>{{businessdata.name}}</td>
</tr>
Whenever there is change in "Type" (From A to B and B to C and C to D and so on), I want to insert a new <tr> for displaying the heading(Type) only for the first time. Can anyone help in this?
Thanks!
You could create create 3 different ng-repeat each for different type.
e.g.
<tr><th>A</th></tr>
<tr ng-repeat="item in data | filter: {Type:'A'}">
<td>{{item.name}}</td>
<td>{{item.id}}</td>
</tr>
<tr><th>B</th></tr>
<tr ng-repeat="item in data | filter: {Type:'B'}">
<td>{{item.name}}</td>
<td>{{item.id}}</td>
</tr>
<tr><th>C</th></tr>
<tr ng-repeat="item in data | filter: {Type:'C'}">
<td>{{item.name}}</td>
<td>{{item.id}}</td>
</tr>
Here's a working plunker
Related
So i want to create a nested table like in this picture ( where a table row can have a tree structure ) , but i'm lost and I have no idea how to do it.
what's the idea and how can i accomplish it?
for example i have this recursive tree and i want to put it inside an expandable table :
{
"id": 1,
"depth": 0,
"value": 3.5,
"name": "root",
"children": [
{
"id": 2,
"depth": 1,
"value": 2.5,
"name": "a",
"children": [
{
"id": 6,
"depth": 2,
"value": 2.0,
"name": "z",
"children": [],
"leafNode": true,
"rootNode": false
},
{
"id": 7,
"depth": 2,
"value": 2.3,
"name": "y",
"children": [],
"leafNode": true,
"rootNode": false
}
],
"leafNode": false,
"rootNode": false
},
{
"id": 4,
"depth": 1,
"value": 0.0,
"name": "c",
"children": [],
"leafNode": true,
"rootNode": false
},
{
"id": 3,
"depth": 1,
"value": 1.0,
"name": "b",
"children": [
{
"id": 5,
"depth": 2,
"value": 1.0,
"name": "d",
"children": [],
"leafNode": true,
"rootNode": false
}
],
"leafNode": false,
"rootNode": false
}
],
"leafNode": false,
"rootNode": true
}
you can use component recursion, you will create component take input object which is same type of children and in its template call it again and pass children of current object
ts file
#Input('obj') obj:any
template file
<tr>
<td>
{{obj.name}}
</td>
</tr>
<tr *ngFor="let child of obj.children , let i=index">
<td>
<app-children [obj]="child"></app-children>
</td>
</tr>
</table> ```
You can check third party components such as PrimeNg Tree table component
Tree table docs
I am trying to display json data in html form using ng-repeat, I was able to grab data but some I could not due to objects in objects structure. Ex : "Obj => Obj => Obj" of a kind.
In the json object below, I have accessed the objs in the "Color" but where I need help is to access the objs in the "seat" and "engine"!. I think whatever ng-repeat that grabs "seat" objs would likely do the same for the "engine".
I did like this: ng-repeat = "c in datasource" first step. Next in a td, I did ng-repeat =" allcolor in c.Color" to get data of that "Color".
Now in another td, I want to grab the data of objs in "seat", how do I go about it?
Ex: ng-repeat = "seatobjs in allcolor.seat" not working.
<tr ng-repeat = "c in datasource">
<td>{{c.Name}}</td>
<td>{{c.From}}</td>
<td ><p ng-repeat="allcolor in c.Color>
{{allcolor.Name}}</p></td>
<td><p ng-repeat="seatobjs in allcolor.seat"> //need help here
{{seatobjs.Name}}</p></td>
<td><button type="button" ng-disabled="!(check)">Edit</button></td>
</tr>
Thank
[
{
"Name": "Car",
"From": "2019-06-26",
"Tom": "2019-12-31",
"Color": [
{
"Name": "Green",
"From": "2019-06-26",
"Tom": "2019-12-31",
"seat": [
{
"Name": "Yello",
"From": "2019-06-26",
"Tom": "2019-12-31"
},
{
"Name": "Green",
"From": "2019-06-26",
"Tom": "2019-12-31"
}
],
"engine": [
{
"Name": "Brown",
"From": "2019-06-26",
"Tom": "2019-12-31"
}
]
}
]
},
{
"Name": "Car",
"From": "2019-06-26",
"Tom": "2019-12-31",
"Color": [
{
"Name": "Red",
"From": "2019-06-26",
"Tom": "2019-12-31",
"tyre": [
{
"Name": "Yello",
"From": "2019-06-26",
"Tom": "2019-12-31"
},
{
"Name": "Green",
"From": "2019-06-26",
"Tom": "2019-12-31"
}
],
"engine": [
{
"Name": "Black",
"From": "2019-06-26",
"Tom": "2019-12-31"
}
]
}
]
},
]
Try this
ng-repeat = "seatobjs in allcolor['seat']"
allcolor cannot be accessed by elements that are outside of the ng-repeat defined element.
With your given HTML markup, you might want to use ng-repeat again on the new td and access seat as follows.
<tr ng-repeat = "c in datasource">
<td>{{c.Name}}</td>
<td>{{c.From}}</td>
<td ><p ng-repeat="allcolor in c.Color>
{{allcolor.Name}}</p>
</td>
<td ng-repeat =" allcolor2 in c.Color">
<p ng-repeat="seatobjs in allcolor2.seat">{{seatobjs.Name}}</p>
</td>
<td><button type="button" ng-disabled="!(check)">Edit</button></td>
</tr>
With the ngRepeat directive you can iterate over the properties of an object. This is the syntax:
<div ng-repeat="(key, value) in myObj">…</div>
The following code iterates some properties of your JSON and binds them inside a table:
var carApp = angular.module('carApp', []);
carApp.controller('CarController', function CarController($scope) {
$scope.cars = [{
"Name": "Car",
"From": "2019-06-26",
"Tom": "2019-12-31",
"Color": [{
"Name": "Green",
"From": "2019-06-26",
"Tom": "2019-12-31",
"seat": [{
"Name": "Yello",
"From": "2019-06-26",
"Tom": "2019-12-31"
},
{
"Name": "Green",
"From": "2019-06-26",
"Tom": "2019-12-31"
}
],
"engine": [{
"Name": "Brown",
"From": "2019-06-26",
"Tom": "2019-12-31"
}]
}]
},
{
"Name": "Car",
"From": "2019-06-26",
"Tom": "2019-12-31",
"Color": [{
"Name": "Red",
"From": "2019-06-26",
"Tom": "2019-12-31",
"tyre": [{
"Name": "Yello",
"From": "2019-06-26",
"Tom": "2019-12-31"
},
{
"Name": "Green",
"From": "2019-06-26",
"Tom": "2019-12-31"
}
],
"engine": [{
"Name": "Black",
"From": "2019-06-26",
"Tom": "2019-12-31"
}]
}]
},
];
});
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.7.5/angular.min.js"></script>
<div ng-app="carApp">
<div ng-controller="CarController">
<table class="table table-bordered">
<thead>
<tr>
<th>Name</th>
<th>Color</th>
<th>Seat</th>
<th>Tyre</th>
<th>Engine</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="car in cars">
<td>{{car.Name}}</td>
<td>
<span>{{car.Color[0].Name}}</span>
</td>
<td>
<ul>
<li ng-repeat="seat in car.Color[0].seat">{{seat.Name}}</li>
</ul>
</td>
<td>
<ul>
<li ng-repeat="tyre in car.Color[0].tyre">{{tyre.Name}}</li>
</ul>
</td>
<td>{{car.Color[0].engine[0].Name}}</td>
</tr>
</tbody>
</table>
</div>
</div>
Am using angular 6, but i don't know how to use *ngFor in html table looping. i need code for below attached screenshot. Also am given API response
{
"result": [
[
{
"title": "Title 1",
"sno": "1",
"name": "abc",
"phone": "123456",
"email": "abc#gmail.com"
},
{
"title": "Title 1",
"sno": "2",
"name": "def",
"phone": "789456",
"email": "def#gmail.com"
},
{
"title": "Title 1",
"sno": "3",
"name": "ghi",
"phone": "4561230",
"email": "ghi#gmail.com"
}
],
[
{
"title": "Title 2",
"sno": "1",
"name": "john",
"phone": "4561230",
"email": "john#gmail.com"
}
]
]
}
Use nested ngFor Loop check the example below:
<table id="spreadsheet">
<tr *ngFor="let data of result">
<td class="row-number-column">{{data[0].title}}</td>
<td *ngFor="let item of data">
<tr>
<td class="row-number-column">{{item.sno}}</td>
<td class="row-name-column">{{item.name}}</td>
<td class="row-name-column">{{item.phone}}</td>
</tr></td>
</tr>
I have a table which shows the below data in the grid.Each value have a column in the table.I displayed all data by calling the api. I dont know how to display the currencies code,name,symbol,languages in the table.Can anyone help me to sort this out?
[
{
"name": "Afghanistan",
"topLevelDomain": [
".af"
],
"currencies": [
{
"code": "AFN",
"name": "Afghan afghani",
"symbol": "؋"
}
],
"languages": [
{
"iso639_1": "ps",
"iso639_2": "pus",
"name": "Pashto",
"nativeName": "پښتو"
},
{
"iso639_1": "uz",
"iso639_2": "uzb",
"name": "Uzbek",
"nativeName": "Oʻzbek"
},
{
"iso639_1": "tk",
"iso639_2": "tuk",
"name": "Turkmen",
"nativeName": "Türkmen"
}
],
"translations": {
"de": "Afghanistan",
"es": "Afganistán",
"fr": "Afghanistan"
}
}
}]
You can just do like:
<table>
<tr>
<td>{{data.name}}</td>
<td>
<span *ngFor="let item of data.currencies">
Code: {{item.code}}
Name: {{item.name}}
Symbol: {{item.symbol}}
</span>
</td>
</tr>
data is the item of your json.
How to get question length while it has been filtered with other value using angular js?
My Plunker
Actually I am trying to get the filtered question length so we have used this Total no of questions:{{question.length}} to get the answer but it's showing overall questions length like:- 4.
If we used a filter like: | filter:{status: 'pending'} there are 2 data's only showing on the table, so I want to show this filtered questions length only and expecting an answer like: 2
Please look at my plunker for reference My Plunker.
My Html:-
<tr ng-repeat="mani in resultValue=((question) | filter:{status: 'pending'}) ">
<td>{{$index + 1}}</td>
<td>{{mani.title}}</td>
<td>{{mani.upvotes }}</td>
<td>{{question.length}}</td>
</tr>
<tr>
<td>sum</td>
<td></td>
<td>{{resultValue | sumOfValue:'upvotes'}}</td>
<td></td>
</tr>
</table>
<p class="color">Total no of questions :{{question.length}} </p>
<p>Total no of upvotes : {{resultValue | sumOfValue:'upvotes'}}</p>
<p>Total no of Open Eyes of [1 values] : {{resultValue | sumOfValue:'openeyes'}}</p>
<p>Total no of Open Eyes of [0 value] : {{resultValue | sumOfZeros:'openeyes'}}</p>
Filter i have used :-
filter:{status: 'pending'})
My data:-
$scope.question = [
{
"_id": "5936a70095e3a85804aae050",
"user": {
"_id": "58072aba0f82a61823c434df",
"displayName": "Table 1",
"roles": [
"admin"
],
"profileImageURL": "./modules/users/client/img/ownprofile/uploads/1f08308f43b0674d61a2cc5d95deb5ef",
"email": "ms#e21designs.com",
"categories": []
},
"__v": 1,
"status": "pending",
"openeyers": ["sarawana#gmail.com"],
"openeyes": 1,
"upvoters": [
"sarawana#gmail.com"
],
"upvotes": 1,
"title": "what is cricket",
"created": "2017-06-06T12:58:40.204Z"
},
{
"_id": "5979a913c999e9302caece15",
"user": {
"_id": "58072aba0f82a61823c434df",
"displayName": "karthi",
"roles": [
"admin"
],
"profileImageURL": "./modules/users/client/img/ownprofile/uploads/1f08308f43b0674d61a2cc5d95deb5ef",
"email": "karthi#e21designs.com",
"categories": []
},
"__v": 1,
"status": "approved",
"openeyers": [],
"openeyes": 0,
"upvoters": [
"sarawana#gmail.com"
],
"upvotes": 1,
"title": "who fan you are",
"created": "2017-06-06T12:58:40.204Z"
},
{
"_id": "5936a70095e3a85804aae050",
"user": {
"_id": "58072aba0f82a61823c434df",
"displayName": "Table 1",
"roles": [
"admin"
],
"profileImageURL": "./modules/users/client/img/ownprofile/uploads/1f08308f43b0674d61a2cc5d95deb5ef",
"email": "karthi#e21designs.com",
"categories": []
},
"__v": 1,
"status": "pending",
"openeyers": [],
"openeyes": 0,
"upvoters": [
"ms#e21designs.com",
"vp#gmail.com"
],
"upvotes": 2,
"title": "best of the day",
"created": "2017-06-06T12:58:40.204Z"
},
{
"_id": "5979a913c999e9302caece15",
"user": {
"_id": "58072aba0f82a61823c434df",
"displayName": "karthi",
"roles": [
"admin"
],
"profileImageURL": "./modules/users/client/img/ownprofile/uploads/1f08308f43b0674d61a2cc5d95deb5ef",
"email": "ms#e21designs.com",
"categories": []
},
"__v": 1,
"status": "approved",
"openeyers": ["ms#e21designs.com"],
"openeyes": 1,
"upvoters": [
"ms#e21designs.com",
"vp#gmail.com","ms#gmail.com"
],
"upvotes": 0,
"title": "he is best",
"created": "2017-06-06T12:58:40.204Z"
},
]
Expecting total no of question is like:- 2, so please check my plunker and update the solution as well, thanks
Update the question length code like this:
<p class="color">Total no of questions :{{((question) | filter:{status: 'pending'}).length}} </p>
Working plunkar link
You can use {{resultValue.length}} where resultValue is the filtered data
<p class="color">Total no of questions :{{resultValue.length}} </p>
Working Plunker: http://plnkr.co/edit/IiI1L6JjnWorIQCaWWIU?p=preview