Last active
August 24, 2017 17:59
-
-
Save workmanw/5640745fb46c6e25ec9a to your computer and use it in GitHub Desktop.
Student Filtering via Computed @each
This file contains 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({ | |
studentDetails: null, | |
// {Property} List of students | |
students: Ember.computed('studentDetails.@each.student', function() { | |
let studentDetails = this.get('studentDetails') || []; | |
return studentDetails.getEach('student').uniq(); | |
}), | |
actions: { | |
filterStudent(student) { | |
this.attrs.filterStudent(student); | |
} | |
} | |
}); |
This file contains 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({ | |
studentDetails: null | |
}); |
This file contains 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({ | |
// {Property} List of details | |
studentDetails: null, | |
// {Property} Filtered student | |
filteredStudent: null, | |
// {Property} Details which have passed the filter | |
visibleDetails: Ember.computed('filteredStudent', 'studentDetails.[]', function() { | |
let studentDetails = this.get('studentDetails') || [], | |
filteredStudent = this.get('filteredStudent'); | |
return filteredStudent ? studentDetails.filterBy('student', filteredStudent) : studentDetails; | |
}), | |
actions: { | |
filterByStudent: function(student) { | |
this.set('filteredStudent', student); | |
} | |
} | |
}); |
This file contains 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.Route.extend({ | |
model: function() { | |
let jack = { id: '1', name: 'Jack' }; | |
let joe = { id: '2', name: 'Joe' }; | |
let jill = { id: '3', name: 'Jill' }; | |
return [ | |
{ student: jack, text: 'Lorem' }, | |
{ student: joe, text: 'Ipsum' }, | |
{ student: jill, text: 'Dolor' }, | |
{ student: jack, text: 'Sit' }, | |
{ student: jill, text: 'Amet' } | |
]; | |
} | |
}); |
This file contains 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
.student-filter { | |
color: #3A4F59; | |
background-color: #CED5D9; | |
padding: 5px 8px; | |
border-radius: 3px; | |
cursor: pointer; | |
} |
This file contains 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
.student-details-table { | |
margin-top: 10px; | |
border-spacing: 0; | |
border-collapse: collapse; | |
} | |
.student-details-table th { | |
min-width: 120px; | |
text-align: left; | |
} | |
.student-details-table thead tr { | |
border-bottom: solid 1px #CED5D9; | |
} |
This file contains 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
{ | |
"version": "0.4.16", | |
"EmberENV": { | |
"FEATURES": {} | |
}, | |
"dependencies": { | |
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js", | |
"ember": "https://cdnjs.cloudflare.com/ajax/libs/ember.js/2.1.0/ember.debug.js", | |
"ember-data": "https://cdnjs.cloudflare.com/ajax/libs/ember-data.js/2.1.0/ember-data.js", | |
"ember-template-compiler": "https://cdnjs.cloudflare.com/ajax/libs/ember.js/2.1.0/ember-template-compiler.js" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment