I have a component with a table and I made my <th></th> tags to be able to sort the data when you click on a th tag the data is being sorted by ASC or DESC
in my component set the click event and the variables:
public sort_by = "name";
public sort_order = "asc";
sortTableBy(sort_by:string){
if(sort_by === this.sort_by){
this.sort_order = (this.sort_order === 'asc' ? 'desc' : 'asc');
}else{
this.sort_order = "asc";
this.sort_by = sort_by;
}
this.updateData();
}
and this is my template HTML
<th>
<div (click)="sortTableBy('name')">
<span>User Name</span>
<i *ngIf="sort_by == 'name' && sort_order == 'desc'" class="fa fa-sort-up"></i>
<i *ngIf="sort_by == 'name' && sort_order == 'asc'" class="fa fa-sort-down"></i>
</div>
</th>
Because I gonna use this table more than once I would like it to be cleaner and I want it to be more or less like that:
<th>
<sortable sortBy="name" value="User Name"></sortable>
</th>
I don't know how to create this type of component and how to communicate between components