Skip to content

Instantly share code, notes, and snippets.

@abueloshika
Created January 16, 2019 15:45
Show Gist options
  • Save abueloshika/2d63f689bc96eef97f0a0f9257f86977 to your computer and use it in GitHub Desktop.
Save abueloshika/2d63f689bc96eef97f0a0f9257f86977 to your computer and use it in GitHub Desktop.
component demo
import Ember from 'ember';
import {
computed
} from '@ember/object';
export default Ember.Component.extend({
init() {
this._super(...arguments);
this.dataSorting = ['total_customers']
this.dataSortingDesc = ['total_customers:desc']
},
sortedDataDesc: computed.sort('unsortedData', 'dataSortingDesc'),
sortedData: computed.sort('unsortedData', 'dataSorting'),
unsortedData: computed('model', function () {
return this.get('model');
}),
actions: {
columnsort(property) {
if (!this.get('tableSorted')) {
this.set('dataSortingDesc', [`${property}:desc`])
this.set('model', this.get('sortedDataDesc'))
this.set('tableSorted', true)
} else {
this.set('dataSorting', [property])
this.set('model', this.get('sortedData'))
this.set('tableSorted', null)
}
},
}
});
import Ember from 'ember';
export default Ember.Component.extend({
});
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle',
model: [{name: "Frank", age: 22}, {name: "Alan", age: 43}, {name: "Bob", age: 56}]
});
<h1>Welcome to {{appName}}</h1>
<br>
<br>
{{my-component model=model}}
{{second-component model=model}}
<br>
<br>
<table>
<thead>
<th {{action "columnsort" "name"}}>Name</th>
<th {{action "columnsort" "age"}}>Age</th>
</thead>
<tbody>
{{#each model as |model|}}
<tr>
<td>
{{model.name}}
</td>
<td>{{model.age}}</td>
</tr>
{{/each}}
</tbody>
</table>
{{#each model as |model|}}
<ul>
<li>{{model.name}} - {{model.age}} </li>
</ul>
{{/each}}
{
"version": "0.15.1",
"EmberENV": {
"FEATURES": {}
},
"options": {
"use_pods": false,
"enable-testing": false
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.js",
"ember": "3.4.3",
"ember-template-compiler": "3.4.3",
"ember-testing": "3.4.3"
},
"addons": {
"ember-data": "3.4.2"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment