mirror of
				https://github.com/datahub-project/datahub.git
				synced 2025-10-31 10:49:00 +00:00 
			
		
		
		
	
		
			
				
	
	
		
			40 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
			
		
		
	
	
			40 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
| import Ember from 'ember';
 | |
| const {
 | |
|   Component,
 | |
|   computed
 | |
| } = Ember;
 | |
| 
 | |
| export default Component.extend({
 | |
|   tagName: 'th',
 | |
|   classNameBindings: ['isColumnActive'],
 | |
|   columnName: '',
 | |
|   sortColumnWithName: '',
 | |
|   sortDirection: null,
 | |
| 
 | |
|   isColumnActive: computed('sortColumnWithName', 'columnName', function () {
 | |
|     const {sortColumnWithName, columnName} = this.getProperties('sortColumnWithName', 'columnName');
 | |
|     return sortColumnWithName && sortColumnWithName === columnName;
 | |
|   }),
 | |
| 
 | |
|   click() {
 | |
|     const {
 | |
|       columnName,
 | |
|       sortDirection,
 | |
|       isColumnActive
 | |
|     } = this.getProperties('columnName', 'sortDirection', 'isColumnActive');
 | |
| 
 | |
|     if (columnName) {
 | |
|       let updatedSortDirection;
 | |
|       // if this column is not active, default sort direction to ascending, else toggle sort direction
 | |
|       if (!isColumnActive) {
 | |
|         updatedSortDirection = 'asc';
 | |
|       } else {
 | |
|         updatedSortDirection = sortDirection === 'asc' ? 'desc' : 'asc';
 | |
|       }
 | |
| 
 | |
|       this.get('sortDidChange')(columnName, updatedSortDirection);
 | |
|       this.set('sortDirection', updatedSortDirection);
 | |
|     }
 | |
|   }
 | |
| });
 | 
