src/grid-header.component.ts
| selector | app-header | 
            
| template |  | 
            
                        Properties | 
                
                        Methods | 
                
                        Inputs | 
                
                        Outputs | 
                
                            constructor()
                         | 
                    
| 
                                     Defined in src/grid-header.component.ts:36 
                                 | 
                            
                            
                            columns
                         | 
                        
                               
                                Type:      | 
                    
| 
                                     Defined in src/grid-header.component.ts:19 
                                 | 
                            |
                            
                            onSort
                         | 
                        
                            $event type:    EventEmitter<ISortResult>
                         | 
                    
| 
                                     Defined in src/grid-header.component.ts:20 
                                 | 
                            |
| sort | ||||||||||||
    sort(column: string, event?: MouseEvent)
                         | 
                    ||||||||||||
| 
                                     Defined in src/grid-header.component.ts:26 
                                 | 
                            ||||||||||||
| 
    
                                 
                                        Parameters :
                                         
                                
 
                                    Returns :      
                                    void
    
                                 | 
                    
| currentSort | 
                            currentSort:     
                         | 
                    
                                Type :     string
    
                             | 
                        
| 
                                     Defined in src/grid-header.component.ts:22 
                                 | 
                            
| currentSortOrder | 
                            currentSortOrder:     
                         | 
                    
                                Type :     number
    
                             | 
                        
                                Default value : 1
                             | 
                        
| 
                                     Defined in src/grid-header.component.ts:23 
                                 | 
                            
| sortClass | 
                            sortClass:     
                         | 
                    
                                Type :     string
    
                             | 
                        
                                Default value : fa fa-sort-desc
                             | 
                        
| 
                                     Defined in src/grid-header.component.ts:24 
                                 | 
                            
import { Component, Input, OnInit, Output, EventEmitter } from '@angular/core';
import { ISortResult } from './ISortResult';
import { IGridColumn } from './IGridColumn';
@Component({
  selector: 'app-header',
  template: `
  <thead>
  <tr>
      <th *ngFor="let column of columns" class="grid-cell grid-header" >
          <span (click)="sort(column.name)">{{column.title}} <span *ngIf="currentSort == column.name"> <i [class]="sortClass"></i></span>
          </span>
      </th>
  </tr>
</thead>
  `
})
export class GridHeaderComponent implements OnInit {
  @Input() columns: IGridColumn[] = [];
  @Output() onSort: EventEmitter<ISortResult> = new EventEmitter();
  currentSort: string;
  currentSortOrder: number = 1;
  sortClass: string = 'fa fa-sort-desc';
  sort(column: string, event?: MouseEvent) {
    if (event) {
      event.preventDefault();
    }
    this.currentSort = column;
    this.currentSortOrder = this.currentSortOrder === 1 ? -1 : 1;
    this.sortClass =
      this.currentSortOrder === 1 ? 'fa fa-sort-desc' : 'fa fa-sort-asc';
    const sort = { column: this.currentSort, order: this.currentSortOrder };
    this.onSort.emit(sort);
  }
  constructor() {}
  ngOnInit(): void {}
}