Skip to content

Instantly share code, notes, and snippets.

@thoov
Last active August 29, 2015 14:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thoov/b626f9e761aed195cd56 to your computer and use it in GitHub Desktop.
Save thoov/b626f9e761aed195cd56 to your computer and use it in GitHub Desktop.
Ember Table built with compossible components. https://github.com/emberjs/ember.js/issues/11124
{{#my-table model=arrayOfData as |table|}}
{{#my-column table=table header='FirstName'}}
{{firstName}}
{{/my-column}}
{{#my-column table=table header='LastName'}}
{{lastName}}
{{/my-column}}
{{#my-column table=table header='FullName'}}
{{firstName}} {{lastName}}
{{/my-column}}
{{/my-table}}
Ember.Controller.extend({
arrayOfData: [{
firstName: 'Bob',
lastName: 'Smith'
},{
firstName: 'Jane',
lastName: 'Doe'
},{
firstName: 'Bill',
lastName: 'Todd'
}]
});
Ember.Component.extend({
init: function() {
this._super.apply(this, arguments);
var table = this.attrs.table.value;
var blockTemplate = this.get('_blockTemplate'); // This does not exist yet
table.registerColumns.call(table, {template: blockTemplate, attrs: this.attrs});
},
// Do not render the block template
render: function() {}
});
{{yield this}}
<table>
<thead>
<tr>
{{#each headers as |header|}}
<th>{{header}}</th>
{{/each}}
</tr>
</thead>
<tbody>
{{#each model as |data|}}
<tr>
{{#each columns as |column|}}
<td>{{component template=column.template attrs=column.attrs context=data}}</td> {{!-- Does not work --}}
{{/each}}
</tr>
{{/each}}
</tbody>
</table>
Ember.Component.extend({
columns: null,
headers: null,
init() {
this._super.apply(this, arguments);
this.setProperties({
columns: Ember.A(),
headers: Ember.A()
})
},
registerColumns: function(columnObject) {
this.get('columns').pushObject(columnObject);
this.get('headers').pushObject(columnObject.attrs.header);
},
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment