Skip to content

Instantly share code, notes, and snippets.

@alecklandgraf
Last active August 7, 2016 04:06
Show Gist options
  • Save alecklandgraf/0a625e4b64330c06ecb7b6bc180c76b8 to your computer and use it in GitHub Desktop.
Save alecklandgraf/0a625e4b64330c06ecb7b6bc180c76b8 to your computer and use it in GitHub Desktop.
statelessTable
/**
* usage:
* <stateless-table
* data="[{first_name: 'Aleck', last_name: 'Landgraf'}, ...]"
* on-header-click="sortData()"
* ></stateless-table>
*/
module.component('statelessTable', {
bindings: {
data: '<',
onHeaderClick: '&'
},
controller: () => {
var ctrl = this;
ctrl.$onInit = () => {
ctrl.columns = keys(ctrl.data[0]);
};
},
template: `
<table>
<tr>
<th
ng-repeat="column in $ctrl.columns"
ng-click="$ctrl.onHeaderClick(column)"
>{{ column }}</th>
</tr>
<tr ng-repeat="row in $ctrl.data">
<td ng-repeat="column in $ctrl.columns">{{ row[column] }}</td>
</tr>
</table>
`});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment