Created
March 17, 2015 08:42
-
-
Save Akii/02a0351f9f7d0572a5af to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Ember from 'ember'; | |
export default Ember.Component.extend(Ember.SortableMixin, { | |
sortProperties: ['id'], | |
sortAscending: true, | |
tableClassNames: 'table table-striped table-hover', | |
headers: [ | |
{ | |
sortKey: 'objectKey', | |
title: 'Title', | |
classNames: 'td-class-names' | |
} | |
], | |
init: function() { | |
this._super(); | |
// todo: first header could be unsortable | |
var firstHeader = this.get('headers')[0]; | |
this.set('sortProperties', [firstHeader.sortKey]); | |
}, | |
tableHeaders: function() { | |
// todo could be written better | |
var headers = this.get('headers'); | |
var sortProperty = this.get('sortProperties')[0]; | |
var sortAscending = this.get('sortAscending'); | |
var sorting = (sortAscending) ? 'sorting_asc' : 'sorting_desc'; | |
var tableHeaders = []; | |
headers.forEach(function(header) { | |
var sortingClassName = (sortProperty === header.sortKey) ? sorting : ''; | |
tableHeaders.push({ | |
sortKey: header.sortKey, | |
title: header.title, | |
classNames: header.classNames + ' ' + sortingClassName | |
}); | |
}); | |
return tableHeaders; | |
}.property('sortProperties', 'sortAscending'), | |
rows: function() { | |
return this.get('arrangedContent'); | |
}.property('sortProperties', 'sortAscending'), | |
actions: { | |
sortBy: function(property) { | |
if (property === this.get('sortProperties')[0]) { | |
this.set('sortAscending', !this.get('sortAscending')); | |
} else { | |
this.set('sortAscending', true); | |
this.set('sortProperties', [property]); | |
} | |
} | |
} | |
}); |
Author
Akii
commented
Mar 17, 2015
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment