How to get table's first column td value in angular 6 - angular6

Tried to get table's first column td value after selected dropdown change values but not working.
I want to get first column td value after selected dropdown in angular 6.
I have given my code below. Anyone can have idea?please help to find the solution.
<table class="table table-striped table-hover" id="wrapperTbl">
<thead>
<tr>
<th>ID</th>
<th>Name</th>
<th>Job</th>
<th>YearJoined</th>
<th>Missions</th>
</tr>
</thead>
<tbody>
<tr *ngFor="let astronaut of astronautsToBeSelected" class="clickable">
<td (click)="selectAstronaut(astronaut)">{{astronaut.id}}</td>
<td (click)="selectAstronaut(astronaut)">{{astronaut.name}}</td>
<td (click)="selectAstronaut(astronaut)">{{astronaut.job}}</td>
<td (click)="selectAstronaut(astronaut)">{{astronaut.year_joined}}</td>
<select (change)="selected()">
<option *ngFor="let mission of astronaut.missions" [selected]="mission.name == 'back'">{{mission}} </option>
</select>
</tr>
</tbody>
Demo:
https://stackblitz.com/edit/how-to-show-the-dynamic-table-with-dropdown-in-angular-todepv?file=app%2Fapp.component.html

You can do the following -
<tbody>
<tr *ngFor="let astronaut of astronautsToBeSelected" class="clickable">
<td (click)="selectAstronaut(astronaut)">{{astronaut.id}}</td>
<td (click)="selectAstronaut(astronaut)">{{astronaut.name}}</td>
<td (click)="selectAstronaut(astronaut)">{{astronaut.job}}</td>
<td (click)="selectAstronaut(astronaut)">{{astronaut.year_joined}}</td>
<td><select (change)="selected($event, astronaut.id)">
<option *ngFor="let mission of astronaut.missions" [selected]="mission.name == 'back'">{{mission}} </option>
</select>
</td>
</tr>
</tbody>
When you want to access any event, you will need the $event in the html. You can also pass additional parameters you want.
selected(event, id){
//tbal id is wrapperTbl
alert(event.target.value + '|' + id )
}
Hope this helps.

Related

Typo3: How do I make a loop for each element in a table?

I have a Typo3(11.5.12) website, with a generated sitepackage and the Fluid Template Engine.
I want to create a dynamic table element in a custom template. It is supposed to create an element for each entry a user makes on a the page in Typo3.
I tried to implement this with a table and I want to make an iterator, that loops once for each element added to this table in the custom html layout. In the loop I want to create an option element containing the text of the table row and a custom ID.
I already made an Iterator with fluid, that loops for each element in an array, so maybe converting the table content to an array might work?
If there is another content module that fits better I would use that, I also considered a simple text element with an iterator for each line.
I made a variable content, which gets the content of said table in the setup.typoscript file.
The table:
The variable in setup.typoscript:
variables{
content < styles.content.get
}
The (current) content of the variable:
<div id="c21" class="frame frame-default frame-type-table frame-layout-0">
<table class="ce-table">
<tbody>
<tr> <td> Testkunde 1 </td> </tr>
<tr> <td> Testkunde 2 </td> </tr>
<tr> <td> Testkunde 3 </td> </tr>
<tr> <td> Testkunde 4 </td> </tr>
<tr> <td> Testkunde 5 </td> </tr>
<tr> <td> Testkunde 6 </td> </tr>
<tr> <td> Testkunde 7 </td> </tr>
<tr> <td> Testkunde 8 </td> </tr>
<tr> <td> Testkunde 9 </td> </tr>
<tr> <td> Testkunde 10 </td> </tr>
</tbody>
</table>
</div>
Snippet from the custom html layout, where I want to implement the iterator:
<table>
<tr>
<td>
<form>
<input type="hidden" name="id" value="4">
<input type="hidden" name="Select" value="All">
<select name="Nr" size="20" style="width:400px;">
<option value="1">Kunde 1</option>
<option value="2">Kunde 2</option>
<option value="3">Kunde 3</option>
<option value="4">Kunde 4</option>
<option value="99"> {content}</option>
<!--I want to create an option element
for each line of the table here-->
</select>
</form>
</td>
</tr>
</table>
When manually rendering a backend-created text table, I built my own fluid view helper for this that wraps TYPO3\CMS\Core\Utility\CsvUtility::csvToArray. Its result can easily be iterated on.

filtering one array from another with ngif

I have two arrays. The first array contain rows in table one of this row name department id and one row has a selection (transfer to another department which contain the second array)
now transfer to should filter to not contain the same first array department, pic may explain more.
when i add *ngIf="DepartmentDTO.dept_id != ALLREQUEST.dept"
i got the list but come null value with list, pic show.
also i if possible to get the list with other filter which
*ngIf="DepartmentDTO.dept_id != ALLREQUEST.dept ; DepartmentDTO.dept_id != 0"
Expected Output
Current Output
<table class="table table-hover">
<tr>
<td *ngFor="let DepartmentDTO of depts">
<label><input class="input1" name="radio" ng-control="depts" type="radio" [value]="DepartmentDTO.dept_id" [(ngModel)]="deptId" (click)="getClinicTotal(DepartmentDTO.dept_id)">
{{DepartmentDTO.dept_name}}<br>
</label></td>
</tr>
</table>
TotalCount ={{total_count}}
<br> Department _id:= {{deptId}} all:= {{all}}, Triage:= {{triage}} , clinics:= {{clinics}} , gb:= {{gb}} , dentail:= {{dentail}}. selectedRow = {{selectedRow}}
<table class="table table-hover">
<thead>
<tr>
<th>qid</th>
<th>qno</th>
<th>dept</th>
<th>Tocken For</th>
<th>Transfer to</th>
</tr>
</thead>
<tbody *ngFor="let ALLREQUEST of AllRequest;let i = index">
<tr *ngIf="deptId==0 || deptId== ALLREQUEST.dept">
<td>
{{ALLREQUEST.qid}}
</td>
<td>
{{ALLREQUEST.qno}}
</td>
<td>
{{ALLREQUEST.dept}}
</td>
<td>
{{ALLREQUEST.dept_name}}
</td>
<td>
<select type="list" name="action" [(ngModel)]="ALLREQUEST.transfer_to" [disabled]="!ALLREQUEST.isEditable">
<option *ngFor="let DepartmentDTO of depts " [value]="DepartmentDTO.dept_id">
<tr *ngIf="DepartmentDTO.dept_id!=ALLREQUEST.dept">{{DepartmentDTO.dept_name}}</tr>
</option>
</select>
</td>
<td>
<button (click)="ALLREQUEST.isEditable=!ALLREQUEST.isEditable" *ngIf="!ALLREQUEST.isEditable" class="btn btn-primary">Action</button>
<button *ngIf="ALLREQUEST.isEditable" (click)="transferToken(ALLREQUEST.qid,ALLREQUEST.transfer_to)" class="btn btn-primary">Save</button>
</td>
</tr>
</tbody>
</table>
i got list
now how can i put it in selection list?
getDept(indx:number){
let array1= this.depts;
let array2= this.AllRequest;
var array = array2.map(function(e) {
var f = array1.filter(a => a.dept_id != e.dept && a.dept_id != 0);
return f.map(function(a) {return a.dept_name;}); //? f.dept_id : 0
});
console.log(array[indx]);
}

How to show information by selecting a date from the list

There are two such models:
note.model.ts:
export class Note{
constructor(
public note_id?:number,
public note_text?: string,
public years?: number
) { }
}
year.model.ts:
export class Year{
constructor(
public years?:number
) { }
}
How can I choose the date (the Year model) from the list to display only the information in the table that matches the date with the selected from select?
<select>
<option type="number" *ngFor="let year of years">
{{ year.years }}
</option>
</select>
<div>
<table>
<thead>
<tr>
<th>Note</th>
<th>Year</th>
</tr>
</thead>
<tbody>
<tr *ngFor="let note of notes">
<td>{{note.note_text}}</td>
<td>{{note.years}}</td>
</tr>
</tbody>
</table>
</div>
In your HTML you can add a click event:
<select>
<option type="number" *ngFor="let year of years" (click)="onYearSelection(year.years)">
{{ year.years }}
</option>
</select>
and iterate through a filtered notes list:
<div>
<table>
<thead>
<tr>
<th>Note</th>
<th>Year</th>
</tr>
</thead>
<tbody>
<tr *ngFor="let note of filteredNotes">
<td>{{note.note_text}}</td>
<td>{{note.years}}</td>
</tr>
</tbody>
</table>
</div>
And in your ts file you can write code to filter the notes list on the basis of the selected year.
filteredNotes = [];
onYearSelection(year){
this.filteredNotes = []
this.filteredNotes = this.notes.filter(note => note.years == year);
}

AngularJS Table is not working as in should

AngularJs table is not working as expected.
I am trying to show the values of "sets" where it contains 10 values.
So what is want to do is that i want to create 10 rows, where it will show "set number" 1 to 10.
But it is displaying all the 10 values in a single rows, how i can make it 10 rows !!
<table st-table="rowCollection" class="table table-striped">
<thead>
<tr>
<th>Sets Number</th>
<th>Score of Sets 1</th>
<th>Score of Sets 2</th>
</tr>
</thead>
<tbody>
<tr>
{% for x in sets %}<td>{{ x }}</td>{% endfor %}
<td><input type="text"></td>
<td><input type="text"></td>
</tr>
</tbody>
</table>
Which is looking like so --
You need to use the ng-repeat directive provided in angular as follows
<tr data-ng-repeat="x in sets">
<td> {{ x }} </td>
<td><input type="text"></td>
<td><input type="text"></td>
</tr>
You can follow the example on http://www.w3schools.com/angular/tryit.asp?filename=try_ng_repeat_array
DEMO: http://plnkr.co/edit/NHfCZ7FgcKGCNpIQVpfU?p=preview

How to add tr or any html tag between two tr

Following is the html that I am using I want to add one tr between first two trs but it is not working.
I want to add a html tag and include class for first two tr. How can I achieve that? I do not want to include the submit button's tr in it.
<table cellspacing="0" id="content-space" class="content-space">
<tr>
<td>
Subscription Plan:
</td>
<td>
<select id="PlanNameId" style="width:auto !Important" name="data[][PlanNameId]">
<option value="4">
Disable
</option>
<option selected="selected" value="2">
Free
</option>
<option value="1">
Bronze
</option>
</select>
</td>
<td>
</td>
</tr>
<tr>
<td>
Auto Upgrade:
</td>
<td>
<select id="SubscriptionSetting" name="data[][SubscriptionSetting]">
<option value="1">
Yes
</option>
<option selected="selected" value="0">
No
</option>
</select>
</td>
<td>
</td>
</tr>
<tr>
<td colspan="2" class="signin-button-containers">
<input type="submit" value="Submit" id="subscriptionsubmit" class="primaryLargeButton">
</td>
</tr>
You can simply get the first tr and then insert the new row right after it. With jQuery this is very easy, but without any libraries it can also be done without too much effort.
$("table tr").first().after("<tr><td>Inserted data</td><td>More data in between</td></tr>")
Example: http://jsfiddle.net/qnu3c0uk/1/
Given:
<table>
<tr>
<td>Text</td>
</tr>
<tr>
<td>Text 2</td>
</tr>
<table>
And that you want to insert a table row (with a cell) after the first table row i would do:
$("table tr:first-of-type").after($("<tr>").append("<td>"));
If you then want to add a class to the first and the new row, i would do:
$("table tr:eq(0),table tr:eq(1)").addClass("row-class");
Or actually combining the two parts to:
var $newRow = $("<tr>").addClass("new-class");
var $firstRow = $("table tr:first-of-type").addClass("new-class");
$firstRow.after($newRow.append("<td>"));